KendoUI: resetting grid data to first page after button click

我的梦境 提交于 2019-11-29 09:33:41

If you are doing server side paging it should be enough doing grid.dataSource.page(1) since this will invoke the read exactly as you already realized.

For some reason, if the page is set to 1 and you set it to 1 again, it will do a read. If it is something other than 1 and you set it to 1, it will just go to that page and not do a read. So to answer your question, you can use this code:

if (grid.dataSource.page() != 1) {
   grid.dataSource.page(1);
}
grid.dataSource.read( {parameter: "value"} );

To perform only a single request you should use the query method of the dataSource. It allows you to create combination of the different methods like filter/page/sort etc.

For example:

dataSource.query({ page: 5, pageSize: 20, sort: { field: "orderId", dir: "asc" } });

Use the DataSource.query() method to pass the page number and your custom input parameters:

$("#btnExtract").bind("click", function(e) {
    var grid = $("#section-table").data("kendoGrid");
    grid.dataSource.query( { page: 1, parameter: "value"} );
});

If you're using server side paging and sorting then you may need to include that information as well:

$("#btnExtract").bind("click", function(e) {
    var grid = $("#section-table").data("kendoGrid");

    var queryParams = {
        page: 1,
        pageSize: grid.dataSource.pageSize(),
        sort: grid.dataSource.sort(),
        group: grid.dataSource.group(),
        filter: grid.dataSource.filter(),
        parameter: "value"
    };

    grid.dataSource.query(queryParams);
});

Define a parameterMap for your Kendo grid DataSource read operation, this comes into the transport element as shown below. Then call grid.dataSource.page(1), this will call read and you should be sorted.

   new kendo.data.DataSource({      
transport: {
                   read: {
                          // ur read
                          },
           parameterMap: function (o, operation) {
                         var output = null;
                         switch (operation) {
                                    case "create":
                                    break;
                                case "read":
                                    output =  {parameter: "value"};
                                    break;
                                case "update":
                                    break;
                                case "destroy":
                                    break;
                        }
                     return output;             }}});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!