How do I find Jqgrid index number?

jqgrid, jquery

Solution

You can use the "getInd" method to find the index of the row you're working with, like so:

var idx = grid.getInd(rowKey);

You can also get the array of ID values from your grid like so (ordered as they are in your grid display):

var dataIDs = grid.getDataIDs();

Together, you can get the id for the next row in your grid:

var nextID = (dataIDs.length < idx+1) ? dataIDs[idx+1] : dataIDs[0];

(Here I assume that if you hit the end of your list, you want to wrap around to the beginning - you get the idea)

Problem

I'm using Jqgrid to display a table, and I have a auto increment primary key as the tables primary key.The data is grouped by an orderDate but I don't know how to access values of the same orderDate through Jqgrid. I use this to find the selected row ``` var rowKey = grid.getGridParam("selrow"); ``` and it returns a value, and if the data was neat I would just add 1 to get the correct index for the data I want, but the values are often far off from each other. I can group the data together in the table through modifying the SQL but the table still seems to retain orderDate as the index. Is there an easy way I can just select the next row of the grid? Or at least find its index? Thanks.

Original source