Kendo grid filtering by DateTime

2 posts, 0 answers
  1. Matt
    Matt avatar
    1 posts
    Member since:
    Jul 2010

    Posted 29 Jul Link to this post

     I have to issues with Kendo grid filtering. I'm using Kendo 2015.2.902 version and installed Kendo.DynamicLinq 1.1.2.0.

    First issue is related on parameters which I received from Kendo grid. Filter data are deserialized into Kendo Filter class in my controller action. After deseralization Value property became array of strings and ToDataSourceResult method throws exception: "Operator '>' incompatible with operand types 'DateTimeOffset' and 'String[]". It was happened for any filtering. I temporarily fixed by removing array and injecting string.

     

    Second issue happened after I "fixed" first one. Method ToDataSourceResult throws exception: "Operator '>' incompatible with operand types 'DateTimeOffset' and 'DateTimeOffset' ".

    I followed http://blog.codebeastie.com/kendo-grid-sorting-and-filtering/ and implemented my controller action as explained. Also I implemented JsonNetValueProviderFactory as described here https://github.com/kendo-labs/dlinq-helpers/issues/6.

    Do you know how can I fix that and is it because of different Kendo versions?

  2. Stefan
    Admin
    Stefan avatar
    276 posts

    Posted 02 Aug Link to this post

    Hello Matt,

    I think the issue lies in the Filter.cs file and the way the dates are serialised. There is a thread in Stack Overflow addressing the same error that may be a good starting point:

    https://github.com/kendo-labs/dlinq-helpers/blob/master/Kendo.DynamicLinq/Filter.cs

    http://stackoverflow.com/questions/2818044/linq-to-sql-dynamic-query-with-date-type-fields

    As one of our DevCraft Complete clients, you may take advantage of the way that the data is filtered and parsed server-side with the Kendo.Mvc.Extensions namespace, which is part of the Kendo.Mvc.dll.

    The Kendo.Mvc.Extensions namespace provides the DataSourceRequest object. The DataSourceRequest object needs to be decorated with the [DataSourceRequest] attribute to transport the Kendo UI Grid request information to the server in the correct format. Using this approach the data is returned to the Kendo UI Grid as correctly parsed JSON (grouped, filtered and sorted). 

    Instead of  public async Task<Kendo.DynamicLinq.DataSourceResult> Handle(Query query)
    use an ActionResult in combination with DаtaSourceRequest/ToDataSourceResult. The server controller will look similar to the code below:

    public ActionResult Handle([DataSourceRequest] DataSourceRequest request)
    {
      var ordenes = _dbContext.OrdenesDist
                     .All();
           ...
      return this.Json(ordenes.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
    }


    More information on using the ToDataSourceResult() extension method is avaialble in the following article:

    http://docs.telerik.com/kendo-ui/aspnet-mvc/helpers/grid/binding/ajax-binding

    Please have in mind that Kendo.DynamicLinq is an open source project, and it is supported only by the community.

    http://www.telerik.com/blogs/kendo-ui-open-sources-dynamic-linq-helpers

    The Kendo UI Team will support you in finding the best solution for your scenario, however, if you wish to handle the server-side without the use of the Kendo.Mvc.Extensions, I can only guide you as far as the Kendo UI Grid request format is concerned as well as the server response format needed for the Kendo UI Grid binding to work.

    Finally, if you decide to keep the Kendo.DynamicLinq, I would recommend using the Kendo UI DataSource transport parameterMap property to its full potential. The Kendo UI Data Source parameterMap is executed before each request and can be used to modify the data in the format expected by the server. Documentation is available at:

    http://docs.telerik.com/kendo-ui/api/javascript/data/datasource#configuration-transport.parameterMap

    Regards,
    Stefan
    Telerik by Progress
     
    Get started with Kendo UI in days. Online training courses help you quickly implement components into your apps.
  3. Kendo UI is VS 2017 Ready
Back to Top