Kendo - saving grid filters by code on a page has problems only with date filter grid columns

I have a kendo grid on my webpage and I am trying to programmatically save grid filters with sessionStorage, and this works for the most part.

The problem that I am facing is that when I put the filter in the date column, when I try to re-apply this filter, when the user goes to this page, it throws an error in one of the anonymous b / c functions, the method toLowerCase()does not exist. The filter works fine if I filter the columns of rows. I can apply several filters and save them in sessionStoragevar and reapply to the grid just fine. I only have problems with date columns.

It took me a while to figure out how to get kendo mesh filters using the syntax:

var theKgridFilters = $("#gridList").data("kendoGrid").dataSource.filter();

Then, to save it to sessionStoragevar, I had stringify()an object, otherwise it will not contain mesh filters in this var:

sessionStorage.setItem('theGridFilters', JSON.stringify(theKgridFilters));

Then, to reapply the filter in the grid, I had to convert the string back to a JSON b / c object, the filter is an object with attributes, so I used this:

if (sessionStorage.theGridFilters) {                            
    gridFilter = sessionStorage.theGridFilters;
    gridFilter = $.parseJSON(gridFilter);
}

which applies to the grid data filter attribute:

filter: gridFilter, 

When I filter the grid in the date column, the error is displayed on this line below:

function anonymous(d, __f, __o) {
    return (d.Last_Modified_Date.toLowerCase() == '2013-01-25t06:00:00.000z')
}

If the field is with a filter Last_Modified_Date. I am new to jQuery, JS, etc., and from what I read, anonymous () fns are created on the fly, so I don’t believe that I can change this.

, - toString() toLowerCase(). , , , , . , kendo.web.js IE.

, :

d.Last_Modified_Date    Wed Jan 25 00:00:00 CST 2013    Object, (Date)

, , fn, : '2013-01-25t06:00:00.000z'.

, , - , . . , , , .

, !

+5
1

, , , JSON.parse JavaScript Date. :

typeof $.parseJSON(JSON.stringify(new Date())); // "string"

Kendo , , .

reviver:

 function dateReviver(key, value) {
    var a;
    if (typeof value === 'string') {
        a = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value);
        if (a) {
            return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4],
                            +a[5], +a[6]));
        }
    }
    return value;
 }

 gridFilter = JSON.parse(gridFilter, dateReviver);
+5

All Articles