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

Grid date formatting from json input

1 Answer 577 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Brandon
Top achievements
Rank 1
Brandon asked on 10 Oct 2013, 02:11 PM
I am looking to format my incoming dates but don't see a suitable way without changing my incoming JSON (which I have standardized on passing as 'time since epoch', new Date().valueOf() ).

Sample Grid Row JSON segment:
{"received_date":1381331366000},
Columns list object:
{ "format": "{0: yyyy-MM-dd HH:mm:ss}", "field": "received_date", "title": "Received" },
My understanding is that the format attribute defined above will specify the output format, however I don't know how to specify a way to accept the incoming milliseconds from epoch as a date object without some interceptor layer injecting itself into the consumption of the JSON.

I would be fine to have a event attached to the datasource in use here and have it mutate the long value into a date object if there isn't a more elegant way to achieve this.

1 Answer, 1 is accepted

Sort by
0
Alexander Popov
Telerik team
answered on 11 Oct 2013, 08:55 AM
Hi Brandon,

You could either use the parameterMap option to convert the timestamp to a Date object or use a column template to do the same and format the result. Here is an example template:  
template: "#= kendo.toString(new Date(parseInt(received_date)), 'yyyy-MM-dd HH:mm:ss') #"

 

Regards,
Alexander Popov
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Brandon
Top achievements
Rank 1
Answers by
Alexander Popov
Telerik team
Share this question
or