KendoUI: resetting grid data to first page after button click

后端 未结 5 1760
心在旅途
心在旅途 2020-12-18 21:29

I have the following scenario:

in my page I have a grid (with pagination) bounded to a datasource. When I click on the button \"Extract\" the grid gets populated (re

相关标签:
5条回答
  • 2020-12-18 21:41

    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" } });
    
    0 讨论(0)
  • 2020-12-18 21:52

    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.

    0 讨论(0)
  • 2020-12-18 21:59

    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"} );
    
    0 讨论(0)
  • 2020-12-18 21:59

    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);
    });
    
    0 讨论(0)
  • 2020-12-18 22:02

    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;             }}});
    
    0 讨论(0)
提交回复
热议问题