admin管理员组文章数量:1410712
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
Share asked Jun 21, 2011 at 8:23 CBC22CBC22 531 silver badge4 bronze badges3 Answers
Reset to default 4$('#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");
}
}
}
本文标签: javascriptjqGrid programmatically navigating to the nextprevious rowStack Overflow
版权声明:本文标题:javascript - jqGrid programmatically navigating to the nextprevious row - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745014412a2637748.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论