Completed
Last Updated: 22 Jan 2021 15:39 by ADMIN
Dave
Created on: 19 Sep 2019 19:36
Category: Grid
Type: Feature Request
8
Support binding of grid columns to DateTimeOffset fields

Hello, 

 

I think there is a bug with the DataTimeOffset field when used in a Grid. It cannot display correctly and is showing something like /Date(1364927400000)/. I have to retrieve my data from database as DateTimeOffset format and then use a new ViewModel to convert the DateTimeOffset values to DateTime values. This is really annoying.

 

Could you let me know if there is a way a DateTimeOffset field can be supported in the grid? Sometimes you do have to display the time zone info.

 

I hope this can be fixed in a future release.

 

Thanks,

Sam

6 comments
ADMIN
Viktor Tachev
Posted on: 22 Jan 2021 15:39

Hi Logan,

 

When binding to DateTimeOffset you can utilize AutoMapper library or custom mapper to bind the values and show them in the Grid. The example and the knowledge base articles illustrate the approach with AutoMapper.

 

Regards,
Viktor Tachev
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Logan
Posted on: 15 Jan 2021 13:50

Display works fine, but filtering still doesn't work for DateTimeOffset?.  Is there a different item i should look at for filtering on DateTimeOffset

Alex Hajigeorgieva's solution seems to work for DateTimeOffset fields, but not for DateTimeOffset<Nullable> fields.

Is there anything similar to 

 filter.descriptor.Member = $"{filter.descriptor.Member}.DateTime";

for DateTimeOffset?  I tried ?.DateTime but get 

Invalid property or field - '{Member}?' for type: {GridViewModel}

 

 

ADMIN
Viktor Tachev
Posted on: 30 Nov 2020 13:54

Hi Levi,

 

We did not add a built-in feature for DateTimeOffset due to some limitations in .NET Framework.

We could add an overload for our pickers that accepts DateTimeOffset and displays it. However, submitting it to the server would not be trivial. The default MVC binder is capable of binding a DateTimeOffset only if the submitted parameter is in the 2017-04-17T05:04:18.070Z format.

If we implement DateTimeOffsetoverload for the pickers we would have to either limit our clients to use only the above format or they would need to implement their own binder which can impact the whole project. 

 

Because of this we provided examples that illustrate how DateTimeOffset can be used with our components.

 

Regards,
Viktor Tachev
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Levi
Posted on: 23 Nov 2020 19:43
This is not completed at all - these are only work arounds. It would be wonderful to have DateTimeOffset support without requiring additional work.
ADMIN
Viktor Tachev
Posted on: 23 Jun 2020 14:16

Hello,

 

We have prepared an example illustrating how DateTimeOffset values can be handled.

 

Knowledge Base

Example

 

Regards,
Viktor Tachev
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
ADMIN
Alex Hajigeorgieva
Posted on: 26 Sep 2019 15:06

Hi, Dave,

The Kendo UI Grid for ASP.NET MVC works with DateTime out of the box, it does not work with DateTimeOffset. Therefore I have changed this to a feature request so people can upvote it. We actually have one like this for the DateTimePicker and I have cast a vote for it on your behalf:

https://feedback.telerik.com/kendo-jquery-ui/1358428-support-binding-of-datetimepicker-to-type-datetimeoffset

However, it is possible to make the DateTimeOffset properties behave like a date in the grid -  e.g. you can use the columns format instead of template and get the built-in filter menu with date pickers for the column. To do this you should trick the grid by using the model and by specifying the type manually:

 .Model(m=> {
        m.Field("OrderDate", typeof(DateTime));
    });

If you have server operations enabled (they are enabled by default), you will need to "translate" the DateTimeOffset to a date here too, before passing it to the ToDataSourceResult() to execute the query:

public ActionResult Orders_Read([DataSourceRequest] DataSourceRequest request)
        {
            ModifyFilters(request.Filters);
            return Json(orders.ToDataSourceResult(request));
        }

        private void ModifyFilters(IEnumerable<IFilterDescriptor> filters)
        {
            if (filters.Any())
            {
                foreach (var filter in filters)
                {
                    var descriptor = filter as FilterDescriptor;
                    if (descriptor != null && descriptor.Member == "OrderDate")
                    {
                       // use this if using just dates
                        descriptor.Member = "OrderDate.Date";
                    }
                    if (descriptor != null && descriptor.Member == "OrderDateWithMinutes")
                    {
                        // use this if time is necessary
                        descriptor.Member = "OrderDateWithMinutes.DateTime";
                    }
                    else if (filter is CompositeFilterDescriptor)
                    {
                        ModifyFilters(((CompositeFilterDescriptor)filter).FilterDescriptors);
                    }
                }
            }
        }

Let me know in case you have further questions.

Kind Regards,
Alex Hajigeorgieva
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.