Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

KendoUI: resetting grid data to first page after button click

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 (reading paginated data through a web service). Then i select "page 2" through grid pagination. Again the web service is invoked to return data.

Now: I would like to click on "Extract" once more, to reload and show data on the first page. I'm not sure which is the best way.

I would like to make just one call to the service (with input parameters) and have pagination index in the grid resetted.

I am now using the following code:

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

but it actually makes two calls to the service.

like image 447
Matteo Piazza Avatar asked Nov 22 '12 08:11

Matteo Piazza


2 Answers

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.

like image 187
OnaBai Avatar answered Oct 21 '22 23:10

OnaBai


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"} );
like image 38
Daniel Lorenz Avatar answered Oct 22 '22 00:10

Daniel Lorenz