Grid Date Filtering - with string dates

2 posts, 0 answers
  1. Bryan
    Bryan avatar
    1 posts
    Member since:
    Oct 2017

    Posted 11 Oct 2017 Link to this post

    Issue:  Date Filtering not working

    Background:  We are sending up dates as strings.  Yes, I could change this, but this would impact many things and cause a lot of other things to have to change.

    The raw data format is yyyy-mm-dd.

    Customers are requesting we change the display of the dates to MM/dd/yyyy.

    This is working fine by setting the template to this:

    "#= kendo.toString(kendo.parseDate(" + thedefs[ischema].index + ", 'yyyy-MM-dd'), 'MM/dd/yyyy') #";

    What does not work is the filtering.  Because the datatype is string, we get the string based operators.

    I switched the datatype on the field (only in the grid, not the data) to "date" and that partly works.  It does show the date operators and we get a date picker.  But, when you filter any date, nothing is returned.

    I dont really want to write a custom date filter.  Are there any other options?

    If not, can you point me in the right direction to a custom filter override?

    Thanks!

    Bryan

     

  2. Stefan
    Admin
    Stefan avatar
    2475 posts

    Posted 13 Oct 2017 Link to this post

    Hello, Bryan,

    Currently, the described result is expected as the Grid is trying to match a date with a string.

    Indeed, the only option will be to make a custom filtering, which can be done on the filter event of the Grid.

    For example, I suggest on the filter event to parse the date back to its original string format and filter with that value, and then the Grid will make a match(with the string operators). Or if the date type is used, then the value has to be converted to date before filtering:

    https://docs.telerik.com/kendo-ui/api/javascript/ui/grid#events-filter

    https://docs.telerik.com/kendo-ui/api/javascript/data/datasource#methods-filter

    filter:function(e){
     //parse the value
    ......
     // use the filter method with the parsed value to filter the Grid
    }

    Another option will be to use serverFiltering and to handle the filtering logic on the server:

    https://docs.telerik.com/kendo-ui/api/javascript/data/datasource#configuration-serverFiltering

    Regards,
    Stefan
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top