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

Date manipulation in tampltes

1 Answer 47 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
OMER
Top achievements
Rank 1
OMER asked on 13 Feb 2014, 02:32 PM
Hi,
This question is regarding something I'm trying to do in a grid, but it is a general question for templates in general.
I have a grid in which I have a template for a column like this:
template: '<span kendo-tooltip k-content="\'#=timeStamp#">#=timeStamp#</span>'
Is there a way to manipulate the timeStamp and add/subtract hours from it?
So for instance, my timeStamp is: 12/5/2013 08:37:56, and in the template it will add a constant to the time which will add a certain amount of time (i.e. 2 hours) so in the grid I'll see 12/5/2013 10:37:56

1 Answer, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 14 Feb 2014, 11:05 AM
Hi Omer,

Generally speaking, Kendo Templates allow the developer to call a JavaScript function and display the result which it returns. In other words you can write your own JavaScript function which modifies the timestamp and call it every time the template is rendered.
'<span>#=modifyTimeStamp(timeStamp)#</span>'
 
function modifyTimeStamp(timeStamp) {
    //modify the date and return the string which you would like the user to see
}


You should have in mind that this approach does not modify the underlying data. This means that if for example the user tries to filter the Grid data, the filter rule will be executed with the non modified data. In case you want to modify directly the timestamp before it is stored in the dataSource please use the parse function of the dataSource.schema.

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