Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1175
igGrid UTC Dates not working
posted

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?

Parents Reply
  • 5513
    Offline posted in reply to Karthik Thiagarajan

    Hello,

    The timezoneOffsets are used in the scenario where you want to show the local representation of a certain DateTime as it is on the server regardless of the timezone of your clients. Please, check the section concerning igGrid, igTreeGrid and igHierarchical grid in this document for more information.

    To trigger this behavior you need your server DateTime objects to be of type Local so that their UTC offset can be extracted. To convert dates which are already in DateTimeKind.Utc to Local you can use their ToLocalTime() method. Additionally, you should not set any DateDisplayType for your columns. Finally your data source end point (the GetGlobalTasks controller in your case) should be decorated with a [GridDataSourceAction] attribute.

    However, as I mentioned, this option only matters if you don't want to show the client representation of that date, but whatever the server time was when an action happened.

    Now, to answer your question - as your DateTime objects are of Kind.Utc, they represent UTC time and therefore their UTC offset is 0. However, as long as your column's DateDisplayType is set to Local, the client's local representation of that UTC time should be displayed. If it is set to DateDisplayType.Local and the column still shows UTC time, that may be a bug in the product version you are using. However, I did try it out last week and couldn't reproduce it. I'll check it again and let you know if I find anything.

    In the meantime, if you have a small sample that reproduces the behavior, even if it doesn't have any DB and only creates dummy DateTime objects, please share it so I can investigate it further. 

    Best regards,

    Stamen Stoychev

Children
No Data