Search code examples
kendo-uikendo-asp.net-mvckendo-listview

formatting date in a kendo listview Template error


I have a Kendo list view which renders a template the listview has a date field. the problem i am facing is formatting the output on the template which is a date field. my template is like this:

<script type="text/x-kendo-tmpl" id="template">

#if(from_tx === '@User.Identity.Name')
{
#
 <div class="chatmsg" >
    <p style="word-wrap:break-word;">${msg_tx}</p>
    <span class="timestamp">Sent: ${msg_dt}</span>
    <span class="timestamp">Seen: ${seen_dt}</span>
 </div>
#
}
else{
#
  <div class="chatmsg sent">
    <p style="word-wrap:break-word;">${msg_tx}</p>
    <span class="timestamp">Recieved ${msg_dt}</span>
  </div>
# 
}#

</script>

i have tried this

#
 <div class="chatmsg" >
    <p style="word-wrap:break-word;"> "#= kendo.toString(${msg_dt}, 'MM/dd/yyyy') #"</p>
    <span class="timestamp">Sent: ${msg_dt}</span>
    <span class="timestamp">Seen: ${seen_dt}</span>
 </div>
#

but this code gives me a template error..

can Anyone help me out with this problem


Solution

  • i think your msg_dt is not a date object try this

    <script type="text/x-kendo-tmpl" id="template">
     <div class="chatmsg" >
        <p style="word-wrap:break-word;"> "#= kendo.toString(kendo.parseDate(msg_dt, 'yyyy-MM-dd'), 'MM/dd/yyyy') #"</p>
        <span class="timestamp">Sent: #= msg_dt #</span>
        <span class="timestamp">Seen: #= seen_dt #</span>
     </div>
    </script>