This question is locked. New answers and comments are not allowed.
Salo Corgan
Top achievements
Rank 1
Salo Corgan
asked on 06 Apr 2010, 10:00 AM
I'm returning a model to the grid via ajax.
Each object in this model has a date in it. I specifically want this date to be presented in UTC (GMT) (which is how it is in the db).
When the javascript is returned to the grid, I notice it looks something like this:
Each object in this model has a date in it. I specifically want this date to be presented in UTC (GMT) (which is how it is in the db).
When the javascript is returned to the grid, I notice it looks something like this:
{"data":[{"Id":31,"Date":"\/Date(1270543677323)\/","Level":"DEBUG"}]}
That date is technically correct, but because javascript doesn't have timezones, it ends up being rendered in the browser's timezone, which is not UTC. And could in fact be anything.
This renders the time incorrect.
I don't want any automatic timezone application to happen - I want the date/times I send to the grid to be rendered as is.
How do I go about this?
Thanks a lot.
8 Answers, 1 is accepted
0
Luke
Top achievements
Rank 1
answered on 07 Apr 2010, 10:05 AM
I'm falling foul of this too. We have clients in three different timezones who want to standardize on "server time".
This post talks about something similar, but we have to use client-side binding as we automatically update the grid content periodically. I'd rather use the timezone offset in my own code than changing the grid's code, but that's not an option - in the databinding event e.data is null and in the databound event e.data is populated but it's too late to make any changes.
This post talks about something similar, but we have to use client-side binding as we automatically update the grid content periodically. I'd rather use the timezone offset in my own code than changing the grid's code, but that's not an option - in the databinding event e.data is null and in the databound event e.data is populated but it's too late to make any changes.
0
Hi,
There are two possible approaches to deal with this case:
Regards,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
There are two possible approaches to deal with this case:
- Use a string property instead of DateTime and format the date as you want
- Use the onRowDataBound event which fires after the grid is bound.
Regards,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Salo Corgan
Top achievements
Rank 1
answered on 07 Apr 2010, 12:21 PM
Thanks for the reply Atanas.
Are these solutions still compatible with sorting and filtering?
Are these solutions still compatible with sorting and filtering?
0
Hi Salo Corgan,
Only the second option will work correctly with filtering and sorting as the type will remain as date time. If the first option is used string sorting and filtering will be applied.
Regards,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Only the second option will work correctly with filtering and sorting as the type will remain as date time. If the first option is used string sorting and filtering will be applied.
Regards,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Salo Corgan
Top achievements
Rank 1
answered on 15 Jul 2010, 11:18 AM
Atanas,
Can you explain a bit more about how option 2) would work?
What should I be doing in onRowDataBound ? The data has already been changed from what I need to work with.
Many thanks.
Can you explain a bit more about how option 2) would work?
What should I be doing in onRowDataBound ? The data has already been changed from what I need to work with.
Many thanks.
0
Jeff
Top achievements
Rank 1
answered on 22 Sep 2011, 02:49 AM
I found an easy solution is to call Format() on the bound date instead of going through any other hassles. I suppose this works because the formatting is performed on the server side and negates the need for javascript to parse the date.
e.g.
e.g.
columns.Bound(t => t.ScheduleDate).Format("{0:MM/dd/yyyy hh:mm tt}");
0
Scott
Top achievements
Rank 1
answered on 15 Nov 2011, 08:01 PM
Atanas,
Can you explain a bit more about how option 2) would work?
What should I be doing in onRowDataBound? Do I actually have to identify the timezone of the local browser and convert the DateTime field back to the original time? I hope not.
I'm hoping there is a better solution than converting the DateTime to a string (which kills sorting and filtering) or binding to the server (which increases response time and overall hits on the db server). I should be able to use AJAX to collect the data and have the DateTime display in a column just as it came from the database.
Can you explain a bit more about how option 2) would work?
What should I be doing in onRowDataBound? Do I actually have to identify the timezone of the local browser and convert the DateTime field back to the original time? I hope not.
I'm hoping there is a better solution than converting the DateTime to a string (which kills sorting and filtering) or binding to the server (which increases response time and overall hits on the db server). I should be able to use AJAX to collect the data and have the DateTime display in a column just as it came from the database.
0
Hi guys,
Georgi Tunev
the Telerik team
Scott, I believe that the following forum thread will be of help - it discusses the same problem and there Atanas provided some additional information and a solution:
http://www.telerik.com/community/forums/aspnet-mvc/grid/grids-and-dates.aspx
Georgi Tunev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now