Completed
Last Updated: 23 Nov 2020 19:43 by Levi
Dave
Created on: 19 Sep 2019 19:36
Category: Grid
Type: Feature Request
5
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

3 comments
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.