Hi all. I hope you guys had fun in ONE conference.I have question about how to handle time zones in Data Grid.
Generally, OutSystems automatically converts time zones of DateTime value.So the values are handled in UTC on server side, and converted into user's time zone when it comes out on client side.
However, this won't happen with DataGrid as the data is converted to JSON (Text type) on server side, before the auto-convert happens.
What should I do to display DateTime value according to user's browser's time zone?
Here are the screenshots of sample data (Sample_Request) displayed in both DataGrid and normal table.Values of CreatedOn column are displayed in UTC on DataGrid, while they're displayed in JST (UTC+9h, my browser's time zone) in table widget.Thanks in advance for your help, and let me know if anything is unclear.
I read that starting from a certain version of the OutSystems DataGrid, the ArrangeData function automatically converts DateTime values to UTC. The version I'm using doesn’t do that, so it’s difficult for me to test.
However, here’s a code snippet that should force the DataGrid to display times in the local timezone instead of UTC. You’ll need to implement this code in the OnInitialize event of the DataGrid and make sure to update the column’s binding accordingly:
Thanks!
You were right. It was ArrangeData action's behaviour.
If I use JSONSerialize action instead, the date will be converted nicely.
I found a forum post mentioning this behaviour.
https://www.outsystems.com/forums/discussion/76997/outsystems-data-grid-arrangedata-no-longer-convert-date-time-to-local-timezone/
According to this, the behaviour in question is a side-effect from addressing another issue.
And the code snippet you gave me worked as well, but I had to manually offset the time zone in it to make it work.It seems "new Date();" will just re-label the UTC date to JST date without offsetting time.
In summary, I have two options to solve my problem:
1. Use the code snippet in DataGridOnInitialize to offset datetime values in grid.
2. Use JSONSerialize in server action instead of ArrangeData.(Maybe this is not recommended)
Anyways, thanks for your help!Cheers!
Hi @Shinichiro Endo ,
Can you show us how you're loading the data into the DataGrid? Are you using the ArrangeData action?
Hi @Mihai Melencu , thanks for replying.
Yeah, I'm using the ArrangeData action in DataAction.
Here's the logic loading data into the DataGrid.It just gets sample data via Aggregate and convert it to JSON.
Before Binding the data to datagrid , you will have to find browsers's timezone offset(in minutes) using javascript JS let offsetmin = new Date.getTimezoneOffset()and convert UTC time +/- offsetmin AddMinutes(yourUTCDateTime, BrowsertimezoneinMinutes)
Hi @Jamal Mohammed , thanks for replying.
Yeah, currently I'm doing almost the same approach (manually offsetting time zone on server side).However passing time zone offset to every DataGrid-related server calls feels less practical for me, because we don't have to do that if it wasn't for DataGrid...right?
Aren't there any way to make DataGrid automatically offset timezone?
Please note that, when you do this on Server side it would give you server timezone. Use Javascript Instead.
Thank you for the great post.
I was having the exact same issue, and I’m so glad I found the solution here.