Warm tip: This article is reproduced from stackoverflow.com, please click
javascript jquery kendo-grid kendo-asp.net-mvc

Avoid filters to be saved with Kendo Grid Options

发布于 2020-04-03 23:38:00

I am saving Grid state as following code does.

//for saving Grid State
function SaveGridSettings() {
    var grid = $("#myGrid").data("kendoGrid");
    localStorage["GridSettings"] = kendo.stringify(grid.getOptions());
}

//for applying Saved State
function setGridSettings() {
    var grid = $("#myGrid").data("kendoGrid");
    var options = localStorage["GridSettings"];
    if (options) {
        grid.setOptions(JSON.parse(options));
    }
}

This also saves some extra things like sorting and filtering. Well I am OK with every thing saved but not with filters.Is there any way you know to avoid saving filters because it causes annoying behavior to users as if last search string fetch no record,then in future the user see empty grid and start yelling at us. Moreover, Export to Excel button also gets removed after the settings applied back to the grid.

Questioner
Sibtain
Viewed
18
Sibtain 2020-02-10 14:03

Here I got the solution for myself by excluding filter object from the Options before saving it.Try this while saving the grid options.

var Options = grid.getOptions();
delete Options.dataSource.filter;
localStorage[name] = kendo.stringify(Options);