This is a migrated thread and some comments may be shown as answers.

Kendo date filtering - help needed

3 Answers 164 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Alan
Top achievements
Rank 1
Alan asked on 03 May 2016, 02:26 PM

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.

3 Answers, 1 is accepted

Sort by
0
Alan
Top achievements
Rank 1
answered on 03 May 2016, 02:37 PM

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.

0
Accepted
Boyan Dimitrov
Telerik team
answered on 05 May 2016, 07:53 AM

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!
 
0
Alan
Top achievements
Rank 1
answered on 09 May 2016, 07:07 PM

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

 

 

Tags
Grid
Asked by
Alan
Top achievements
Rank 1
Answers by
Alan
Top achievements
Rank 1
Boyan Dimitrov
Telerik team
Share this question
or