How can one get the ID's of every row in a grid, even across pages?
getDataIDs
and getRowData
only gives the ID's of the current page.
Thanks!
How can one get the ID's of every row in a grid, even across pages?
getDataIDs
and getRowData
only gives the ID's of the current page.
Thanks!
It is possible only if you have local grid (
datatype:'local'
or havingloadonce:true
). In the case all data inclusive ids for all pages are already locally. In the case you can use_index
parameter, which will be used typically together with another more known parameterdata
. Withyou will get the
_index
parameter. It is an object which has as the properties all ids of grid. So you can enumerate the ids withThere is another way of getting this data in older versions on
jqgrid
:In later versions of jqGrid they came out with a function that suits this situation better as it will consider any toolbar filtering that may be in place. See Oleg's example here. Thus, if you have a jqGrid (loadonce:true and/or datatype:local) the following will return all row ids (displayed in current page and beyond) which match the current filtering.
This returns a plain array, unlike the original answer, which returns an object with properties that must be enumerated.
Considering that Object.keys is supported since IE9, if you only need the IDs, nowadays I would use:
But please also read and upvote Oleg's answer because it has the conditions in which it's possible to do this and the important information.
Warning for jqgrid version < 4.7:
If you are dynamically removing rows from the grid (
delRowData
), the_index
will still have the deleted rows. You may fix that by fixing "refreshIndex" injqgrid.base.js
(as they did in 4.7).