Skip to content Skip to sidebar Skip to footer

Presetting Kendo Datasource Pagesize To "all"

Whenever a user changes the pagination on a grid, I save the setting in localStorage and retrieve it to set it back whenever the user navigates again to the page. To retrieve it I

Solution 1:

To answer the question. This appears to be a bug in Kendo. Setting the pageSize to 0 (shortcut for "all") after the dataSource was already bound will always result in the grid having issues with any custom filters declared inside of a toolbar template.

To be exact, if you have a custom filter defined inside of the toolbar template:

@(Html.Kendo().TextBox().Name("Filter").Deferred())

You wire it up through the dataSource definition on the grid like:

.DataSource(ds =>
    ds.Ajax()
        .PageSize(defaultPageSize)
        .Read(a => a.Action(actionName, controllerName, new
        {
            param = Model.param
        }).Data("getFilterParameters")))

in javaScript fetching the parameters like:

getFilterParameters: function () {
    returnthis.filterParameters;
},

populating them with a method:

filter: function () {
    var grid = $("#Grid").data("kendoGrid");

    this.filterParameters = {
        param: $("#Filter").val()
    };

    grid.dataSource.page(1);
}

that has a simple event listener wired to it:

$("#Filter").on("keyup", filter);

Then after changing the pageSize programatically to 0/"all" with:

$("#Grid").data("kendoGrid").dataSource.pageSize(0);

The filter will start to always return NaN as the current page / skip of the filter object passed to the server with the query parameters (even though grid will display the numbers correctly). This will cause a "string is not in correct format" exception inside framework code on the endpoint whenever you try using the filter. A solution to the above is to slightly modify the getFilterParameters method:

getFilterParameters: function (e) {
        // Workaround for Kendo NaN pager values if pageSize is set to All if (isNaN(e.page)) e.page = 1;
        if (isNaN(e.skip)) e.skip = 0;
        //returnthis.filterParameters;
    }

This will re-initialize the page and skip values before submitting the filter request. These values will anyway be re-populated on the endpoint with the correct values. Wasn't me who noticed it but another developer working on the project, credit goes to her.

Post a Comment for "Presetting Kendo Datasource Pagesize To "all""