javascript - jqGrid programmatically navigating to the nextprevious row - Stack Overflow

admin2025-04-19  0

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 badges
Add a ment  | 

3 Answers 3

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");
        }
    }
}
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1745014414a280001.html

最新回复(0)