Kendo date filtering - help needed

4 posts, 1 answers
  1. Alan
    Alan avatar
    12 posts
    Member since:
    Apr 2013

    Posted 03 May Link to this post

    I'm having trouble getting date filtering to work. Apologies if this has been answered in another post; searched but didn't find anything that worked for me.

     

    Here's what I have:

    My data is JSON and looks like this:

    [

    {
            "Version": “Initial”,  
            "VersionDate": "2016-04-15T13:15:37Z",
    },
    {
            "Version": “Revision”,  
            "VersionDate": "2016-04-18T14:15:37Z",
        }

    ]

    Here's my relevant grid setup:

    $("#grid").kendoGrid({
        dataSource: {
                      transport: {
                            read: {
                                  url: dataUrl //returns the JSON as seen above,

                            }
                      },
                      schema:  {
                            model: {
                                  fields: {
                                        Version: { type: "string" },
                                        VersionDate: { type: "date" }
                                }
                           }
                   } 
        columns: [                 
                field: "Version",
                title: "Version"
            }, {
                field: "VersionDate",
                title: "Date",
                format: "{0:MM/dd/yyyy}",
                    filterable: {
                                    ui: function(e) {
                                         element.kendoDatepicker({
                                              format: “MM/dd/yyyy”
                                         })
                                   }
                    }
            }
        ],
        filterable: true
        }
    });

    My issue:

    The dates display in the desired format in the grid, e.g. 04/15/2016; and the filter ui allows me to choose dates with a datepicker in the same format. However, when I filter I get no results. I'm assuming this is because the filtering works on the original data which is a string and is not finding a match because of the different format. What do I need to do in order to get date filtering to work properly? Do I need to do a parse function in my schema set up or some combination of things?

    Another note - if I set this up using grid row filtering, I get the following error in console and never see the no results message:

    TypeError: n.toLowerCase is not a function

    I assume again this has to do with the original data being a date in string format, just can't seem to find the correct set up option(s) to make filtering work.

    Please let me know if I need to provide further information; screenshots, example file, etc.

  2. Alan
    Alan avatar
    12 posts
    Member since:
    Apr 2013

    Posted 03 May Link to this post

    Additional information...

    It seems to be that I get 'no results' if filtering option is set to "equal to". If I choose another operator such as "if after" or "if before" I will get results.

  3. Kendo UI is VS 2017 Ready
  4. Answer
    Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 05 May Link to this post

    Hello Alan,

    Indeed the columns.format option only visually modifies what is shown in the column cell. Operations such as filtering, grouping, sorting and etc are handled on DataSource level against the original data. In order filtering to be performed as you expect I would suggest to use the schema.parse function. It is executed before the server response is used and can be used it to preprocess or parse the server response.

    With regards to the second question - the VersionDate date field should be parsed as a date considering the schema.model configuration. Could you please provide a sample dojo example that replicates the problem? 

    Regards,
    Boyan Dimitrov
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  5. Alan
    Alan avatar
    12 posts
    Member since:
    Apr 2013

    Posted 09 May in reply to Boyan Dimitrov Link to this post

    Boyan,

    Thanks for the response. Based on your info, and since the original data I was getting back included a time element, I ended up just changing the response to return a date without the time element. Then I was just used a column template to change the date string to a date object and render. I'm now able to sort, filter,etc.

    Doing this also also removes the error I was getting in regards to my second question about enabling filter row. I am marking this as answered, but will try to provide a dojo instance as requested to try and show the error I was getting.

     

    Regards,

    Alan

     

     

Back to Top
Kendo UI is VS 2017 Ready