When I have a currently selected row in my jqgrid, and I have buttons that say "Next" and "Previous", how do I programmatically do that? Upon initial investigation, I'll need to get the ids of the rows but is there a way to do this by just using the index of the current selected row in the grid?
The ids in my rows are not sequential and are of random values.
Thanks
When I have a currently selected row in my jqgrid, and I have buttons that say "Next" and "Previous", how do I programmatically do that? Upon initial investigation, I'll need to get the ids of the rows but is there a way to do this by just using the index of the current selected row in the grid?
The ids in my rows are not sequential and are of random values.
Thanks
$('#btnNext').click(function () {
var grid = $("#grid").jqGrid({...});
var selectedRow = grid.getGridParam('selrow');
if (selectedRow == null) return;
var ids = grid.getDataIDs();
var index = grid.getInd(selectedRow);
if (ids.length < 2) return;
index++;
if (index > ids.length)
index = 1;
grid.setSelection(ids[index - 1], true);
});
According to http://www.trirand./jqgridwiki/doku.php?id=wiki:events, there's row index property but it doesn't get passed in to onSelectRow event. Perhaps you could get to the row object via its ID and check whether it has a row index, possibly called iRow. From there you'll just have to find the next row by row index iRow+1.
var rowId;
var previousRecord = false;
var array;
function initGrid() {
array = $(ProspectsGrid).jqGrid('getDataIDs');
var i = 0;
if (previousRecord == true)
i = array.length-1;
$(ProspectsGrid).setSelection(array[i]);
rowId = array[i];
}
function GetNextRecord() {
previousRecord = false;
if (rowId != array[array.length - 1]) {
var i = 0;
while (rowId != array[i]) {
i++;
}
i++;
$(ProspectsGrid).setSelection(array[i]);
rowId = array[i];
}
else {
var currentPage = ProspectsGrid.getGridParam("page");
if (currentPage < ProspectsGrid.getGridParam("lastpage")) {
ProspectsGrid.setGridParam({
page: currentPage + 1
});
ProspectsGrid.trigger("reloadGrid");
}
}
}
function GetPreviousRecord() {
previousRecord = true;
if (rowId != array[0]) {
var i = 0;
while (rowId != array[i]) {
i++;
}
i--;
$(ProspectsGrid).setSelection(array[i]);
rowId = array[i];
}
else {
var currentPage = ProspectsGrid.getGridParam("page");
if (currentPage > 1) {
ProspectsGrid.setGridParam({
page: currentPage - 1
});
ProspectsGrid.trigger("reloadGrid");
}
}
}