This is a migrated thread and some comments may be shown as answers.

using formating on a date within a clienttemplate

4 Answers 1124 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Phil
Top achievements
Rank 1
Phil asked on 10 Dec 2012, 04:36 PM
how would I format this AND use it in a ClientTemplate?

        columns.Bound(t => t.CreationDate)
        .Title("Date / Time")
        .Format("{0:dd-MMMM-yyyy}");
        //.ClientTemplate(
        //"<span>CreationDate</span>"
        //); 

4 Answers, 1 is accepted

Sort by
0
Brendon
Top achievements
Rank 1
answered on 12 Dec 2012, 03:21 AM
Ran into this same thing recently and found this somewhere (but not sure where)...There is a Kendo function you can use to format column fields in a ClientTemplate:

#=kendo.toString(ColumnName,'yyyy-MM-dd')#

Full template example:

columns.Template(@<text></text>).ClientTemplate("#=kendo.toString(ColumnName,'yyyy-MM-dd')#");

Column name is of course the bound column. If you still want to be able to sort on the field, add it as a bound column as well.

columns.Bound(e => e.ColumnName).Template(@<text></text>).ClientTemplate("#=kendo.toString(ColumnName,'yyyy-MM-dd')#");
Hope that helps.
0
Rachel
Top achievements
Rank 1
answered on 28 Jan 2015, 01:12 PM
Thank you so much! Hours saved..
0
Toby
Top achievements
Rank 1
answered on 05 Mar 2020, 02:25 PM

If the column is part of a detailgrid you will need to escape the '#' like below  Hopefully this can save someone some time 

 

columns.Bound(o => o.ReceiveDt).ClientTemplate("\\#= kendo.toString(kendo.parseDate(ReceiveDt),'MM/dd/yyyy hh:mm tt') \\#");

0
Petar
Telerik team
answered on 09 Mar 2020, 10:12 AM

Hi Toby,

Thank you for sharing your knowledge with the community! More about the Hash literals escaping can be read on this article from our documentation. 

Regards,
Petar
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
Phil
Top achievements
Rank 1
Answers by
Brendon
Top achievements
Rank 1
Rachel
Top achievements
Rank 1
Toby
Top achievements
Rank 1
Petar
Telerik team
Share this question
or