I've read all of the articles for UTC dates for the newer versions but they aren't working.
MVC v4.17.2.183
Here's what I got:
@(Html.Infragistics().Grid<TaskModel>() .PrimaryKey("TaskApprovalId") .ID("GlobalTasksGrid") .AutoGenerateColumns(false) .AutoGenerateLayouts(false) .EnableUTCDates(true) .Columns(column => { column.For(m => m.TaskApprovalId).DataType("number").HeaderText(" ").Hidden(true); column.For(m => m.Location).DataType("string").Width("215").HeaderText("Location"); column.For(m => m.Task).DataType("string").Width("195").HeaderText("Task").Template("[Task Name]"); column.For(m => m.Employee).DataType("string").Width("155").HeaderText("Employee").Template("[Employee Name]"); column.For(m => m.ApprovalDate).DataType("date").Format("dateTime").Width("180").HeaderText("Date") .Template("<div align='center'>${ApprovalDate}</div>").DateDisplayType(DateDisplayType.Local); }) .Features(feature => { feature.Updating() .EnableAddRow(false) .EnableDeleteRow(true) .EditMode(GridEditMode.None); }) .AutoCommit(true) .DataSourceUrl(Url.Action("GetGlobalTasks")) .DataBind() .Render() )
EnableUTCDates set to true. This notifies the datasource that the incoming date are in UTC format. So it should convert it into a Date object.
LocalSchemaTransform is set to true by default, which is what we want.
The ApprovalDate column is set to DateTime and the DateDisplayType is set to "local".
Unfortunately, the desired result is still the same. The UTC date stored in the database is still rendered as such to the client.
Here's the data coming from the server:
The only thing that stands out is the Metadata.timezoneOffset which I don't set myself.
Thoughts?
So I've read a few other articles:
https://ko.infragistics.com/community/forums/f/ignite-ui-for-javascript/111827/convert-utc-time-to-browser-timezone-in-iggrid
This particular one pointed to DateTime.Kind being set to Unspecified with Entity Framework. So far that assumption is true. I checked the code and sure enough it was set to that. So I changed it programmatically before serialization to Utc. But now the dates render in the UI another 5 hours past than what it is supposed to be. Date was set at 2019-10-15T22:34:02.513Z but I actually did it at 17:34:02 local time.
Seems to be going 5 hours in the wrong direction. Now I'm completely stumped. In addition, I would expect that if I change the DateDisplayType from UTC to Local I would see the dates change but I don't.
Funny thing...setting up a formatter function and then manually setting the date works. This answer isn't correct because the documentation states it can do what I want out of the box. But here's what I applied:
function formatApprovalDate(val, record) { return $.ig.formatter(new Date(val), "date", "dateTime", null, false, null); }
@(Html.Infragistics().Grid<TaskModel>() .PrimaryKey("TaskApprovalId") .ID("GlobalTasksGrid") .AutoGenerateColumns(false) .AutoGenerateLayouts(false) .EnableUTCDates(true) .Columns(column => { column.For(m => m.TaskApprovalId).DataType("number").HeaderText(" "); column.For(m => m.Location).DataType("string").Width("215").HeaderText("Location"); column.For(m => m.Task).DataType("string").Width("195").HeaderText("Task"); column.For(m => m.Employee).DataType("string").Width("155").HeaderText("Employee"); column.For(m => m.ApprovalDate).DataType("string").Width("90").HeaderText("Date").FormatterFunction("formatApprovalDate") .Template("<div align='center'>${ApprovalDate}</div>"); }) .Features(feature => { feature.Updating() .EnableAddRow(false) .EnableDeleteRow(true) .EditMode(GridEditMode.None); feature.Hiding() .ColumnSettings(settings => { settings.ColumnSetting().ColumnKey("TaskApprovalId").Hidden(true).AllowHiding(false); settings.ColumnSetting().ColumnKey("Location").AllowHiding(false); settings.ColumnSetting().ColumnKey("Task").AllowHiding(false); settings.ColumnSetting().ColumnKey("Employee").AllowHiding(false); settings.ColumnSetting().ColumnKey("ApprovalDate").AllowHiding(false); }); }) .AutoCommit(true) .DataSourceUrl(Url.Action("GetGlobalTasks")) .DataBind() .Render() )