jqGrid以编程方式导航到下一行/上一行

时间:2011-06-21 08:23:11

标签: javascript jquery jqgrid

当我在jqgrid中有一个当前选中的行时,我的按钮会显示“Next”和“Previous”,我该如何以编程方式执行此操作?在初步调查时,我需要获取行的ID,但有没有办法通过使用网格中当前所选行的索引来执行此操作?

我的行中的ID不是连续的,而是随机值。

由于

3 个答案:

答案 0 :(得分:2)

$('#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);

});

答案 1 :(得分:0)

根据http://www.trirand.com/jqgridwiki/doku.php?id=wiki:events,有行索引属性,但它不会传递给onSelectRow事件。也许您可以通过其ID访问行对象,并检查它是否有行索引,可能称为 iRow 。从那里你只需要按行索引iRow + 1找到下一行。

答案 2 :(得分:0)

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");
        }
    }
}