Select a row in jqGrid based on cell value
In the loadComplete:
portion of your jqGrid you could iterate over each row and test for the value you are looking for. If the value is found, select the row.
Ex
loadComplete: function () {
var rowIds = $(this).jqGrid('getDataIDs');
for (i = 1; i <= rowIds.length; i++) {
rowData = $(this).jqGrid('getRowData', i);
if (rowData['Id'] == idSearchValue ) {
$(this).jqGrid('setSelection',i);
} //if
} //for
...
There would also be the rowattr:
but I can't seem to find where you can get the rowID of the current row. Oleg might see this and respond as well as it was his addition to jqGrid but I didn't have any luck with my testing or read though of where you would get the current rowId to pass to the setSelection
method.
Comments
-
Sameet almost 2 years
colModel: [ { name: 'Id', index: 'Id', hidden: true, search: false }, { name: 'Name', index: 'Name', hidden: true, search: false }, ]
Just as the setSelection method allows selection of a row in jqGrid based on the row number, is it possible to similarly select a row based on one of the cell values.
For e.g. in the colModel above, is it possible to select a row having a certain 'Id' or 'Name' value...assuming that these values are unique for each row.
-
Oleg about 11 yearsDo you use
multiselect: true
option or you want just highlight (with some color, background color or by adding special CSS class) the rows in the grid? -
Mark about 11 years@Oleg Is there a way to get the current rowId from the rowattr method?
-
Sameet about 11 years@Oleg - using multiselect: true...
-
Oleg about 11 yearsI think that the answer could be interesting for you.
-
Oleg about 11 years@Mark:
rowattr
have no comfortable way to access toid
. One have to get it from the second parameter (or from the first one in some cases). One can modify the line of code to addid
as the third parameter ofrowattr
.
-
-
Oleg about 11 yearsOne can't use current implementation of jqGrid to set selection inside of
rowattr
or by usage ofcellattr
etc. See the thread about the subject. Mark, you can improve the code from your answer if you would use$(this).jqGrid("getCol", "Id", true)
. -
Mark about 11 yearsInteresting... I always learn from your answers! I'll have to look to use that I need to iterate over grid rows!
-
Sameet about 11 years@Mark - So iterate over each row and select the ones that match the criteria...thanks for the direction
-
IcedDante almost 9 yearsJust to spare a lot of frustration among people who copy and paste code, I think you should locally declare/scope the variables in this snippet.
var i;
var rowData;
, etc