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

Grid client template and date formats

7 Answers 1901 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dima
Top achievements
Rank 1
Dima asked on 04 Mar 2013, 06:15 AM
Hi,

How can I  format my date to MM/dd/yyyy in client template? It seems that Format method doesn't work for client templates. Also, I need to sort column that contains date.

Thanks in advance,
Dzmitry Shmidt

7 Answers, 1 is accepted

Sort by
0
Accepted
Nikolay Rusev
Telerik team
answered on 04 Mar 2013, 08:46 AM
Hello Dzmitry,

When using template the formation must be handled within the template. For example:

{
 field: "BirthDate",
 title: "Birth Date",
 template: '#= kendo.toString(BirthDate,"dd/MM/yyyy") #'
}

You can find more details by inspecting the code in the following demo:
http://demos.kendoui.com/web/grid/index.html
http://docs.kendoui.com/getting-started/framework/globalization/dateformatting
All the best,
Nikolay Rusev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Dima
Top achievements
Rank 1
answered on 04 Mar 2013, 02:14 PM
Thanks Nikolay for you reply,
Sorry but i didn't mention, that i used asp.net mvc and want to write as little javascript code as possible. Now when i used date time it's displayed as /Date(.......)/ format. Is there any way to do this on the server and don't use javascript.

Thanks in advance,
Dzmitry Shmidt
0
Nikolay Rusev
Telerik team
answered on 05 Mar 2013, 12:15 PM
Hello Dzmitry,

If you describe the fields in the DataSource.schema and mark them with correct types it will automatically convert those values to correct JavaScript types. For more details see the configuration for the date field in the following demo:
http://demos.kendoui.com/web/grid/remote-data.html

Regards,
Nikolay Rusev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Raimundo
Top achievements
Rank 2
answered on 02 Apr 2015, 06:30 PM
Nikolay if we use CLIENTTEMPLATE, with AJAX, your answer (http://demos.kendoui.com/web/grid/remote-data.html) doesn't fix the problem.

Could you provide some code about it, with Razor?

0
Raimundo
Top achievements
Rank 2
answered on 02 Apr 2015, 06:32 PM
Nikolay if we use CLIENTTEMPLATE, with AJAX, your answer (http://demos.kendoui.com/web/grid/remote-data.html) doesn't fix the problem.

Could you provide some code about it, with Razor?

For instance:

.ClientTemplate(
string.Format("<spam style='background-color: green; text-align:right;'>{0:yyyy}}</spam>", "#:ShipDate#")
);
0
Kiril Nikolov
Telerik team
answered on 06 Apr 2015, 02:23 PM

Hello Raimundo,

What my colleague suggested is to set the type of the data that you get from the server to be date, so the Grid will know to parse the data to valid JavaScript objects. How to define a model is explained here:

http://docs.telerik.com/kendo-ui/api/javascript/data/model#configuration-Define

If this does not help, please send us a send a runnable sample and we will be happy to help.

Regards,
Kiril Nikolov
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
0
Imran
Top achievements
Rank 1
answered on 23 Jul 2015, 06:54 AM

This thing worked for me good

 

c.Bound(p => p.datetimecalculated).Format("{0:dd-MM-yyyy}");​

Tags
Grid
Asked by
Dima
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Dima
Top achievements
Rank 1
Raimundo
Top achievements
Rank 2
Kiril Nikolov
Telerik team
Imran
Top achievements
Rank 1
Share this question
or