Set page in jqgrid
Asked Answered
C

1

6

I've got the following code to change the page of the Jqgrid.

function setPage() {
    $('#editGrid').setGridParam({ page: 10 }).trigger('reloadGrid');
    alert("Success");
}

I get the success message but the page wont change. Currently I run the function in the loadcomplete section of the grid.

Any help would be appreciated.

Chrissy answered 23/2, 2012 at 7:31 Comment(2)
Just for the record. I've also tried to set the datatype to json because I use loadonce: true. $("#editGrid").setGridParam({datatype:'json', page:10}).trigger('reloadGrid');Chrissy
For everyone who is wondering; the way to do this seems to be the following: $("#editGrid").trigger("reloadGrid", [{ page: 10}]); I'm still struggeling to make this work on load, but if I try to put it in onSelectRow etc. it works just fine.Chrissy
C
9

The .trigger('reloadGrid') will reload the grid to page 1. So you did setGridParam({page:10}) but then right after .trigger('reloadGrid') refreshed the grid to page 1.

To set the grid to page 10 do this:

$("#editGrid").trigger("reloadGrid",[{page:10}]);
Canard answered 23/2, 2012 at 16:36 Comment(5)
is it possible to set the page number dynamically? ie I want the number 10 in $("#editGrid").trigger("reloadGrid",[{page:10}]); to be dynamic and it should increment by 1.Tweeddale
@SK11 use a JS variable instead of the fixed number i.e. $('#editGrid').trigger("reloadGrid", [{page:intPage}]);Preexist
@SK11 Sorry I didn't respond. SaschaM78 is correct. You can have a variable that keeps the current page then increase it on next page. i.e. intPage++; or intPage = intPage + 1; Then you can set the page like SaschaM78 did above.Canard
.trigger('reloadGrid') does not reset the page to 1 for me. It stay on the same page.Vav
Correct. This is because the value for the jqGrid Param is the current page. It uses that to reload the grid. So in the example I set {page:10}.Canard

© 2022 - 2024 — McMap. All rights reserved.