Reputation: 47
I have a jqGrid showing some data from server (php query, json results).
Is it possible to get the rowid of a specific row knowing the value stored in a column cell and use setSelection to highlight that row?
I try to better explain with an example: the users of my application select a value from a dropdown menu using form. Then, if this value is in the grid, the row that contains it become highlighted (and, if possible, the grid moves itself to show the highlighted row in the visible portion of the grid window)
Some notes: The grid pager is configured but all rows are in the first page... so pagination would not be a problem
The highlight/selection acts on only one row a time, no multiselect (at the moment)
Thanks in advance
Upvotes: 2
Views: 3265
Reputation: 1758
I think this JavaScript function will do the work for you:
function check(){
var data=$('#dropDown option:selected').val();
var allRowsOnCurrentPage = $('#grid').jqGrid('getDataIDs');
//suppose the column you want tho check in dropdown and in grid is "Name"
for( var i=0;i<allRowsOnCurrentPage.length;i++){
var Name=getCellValue(allRowsOnCurrentPage[i],'Name');
if(Name===data){
jQuery("#grid").setSelection(allRowsOnCurrentPage[i], true);
}
}
}
Upvotes: 2
Reputation: 47
Thank you! I have had to edit a little your function to make it work... here the code that worke:
function check() {
var data=$('#dropDown option:selected').val();
var allRowsOnCurrentPage = $('#grid').jqGrid('getDataIDs');
for( var i=0;i<allRowsOnCurrentPage.length;i++){
var Name = $('#grid').getCell(allRowsOnCurrentPage[i], 'Name');
if(Name===data){
jQuery("#cetacei_grid").setSelection(allRowsOnCurrentPage[i], true);
}
}
Upvotes: 1