Does anyone know how to get the cells value of the selected row of JQGrid ? i m using mvc with JQGrid, i want to access the value of the hidden column of the selected row ?
-
You can visit bellow thread. It has complete answer https://stackoverflow.com/a/62043961/3073945 – Md. Sajedul Karim May 27 '20 at 13:19
6 Answers
First you can get the rowid
of the selected row with respect of getGridParam
method and 'selrow' as the parameter and then you can use getCell to get the cell value from the corresponding column:
var myGrid = $('#list'),
selRowId = myGrid.jqGrid ('getGridParam', 'selrow'),
celValue = myGrid.jqGrid ('getCell', selRowId, 'columnName');
The 'columnName'
should be the same name which you use in the 'name'
property of the colModel
. If you need values from many column of the selected row you can use getRowData instead of getCell.

- 220,925
- 34
- 403
- 798
-
what i have to do if i want to get the value from the subgrid ? just do the same with the subgrid id ? – Saad Aug 09 '11 at 11:21
-
@Saad: There are different ways how you can use subgrid. In case of the usage [subgrid as grid](http://www.trirand.com/jqgridwiki/doku.php?id=wiki:subgrid_as_grid) the subgrid is just another grid so you can do with it everything like with the main grid. Every grid will be typically identified by the id of the corresponding `
` element. So you should just use the id of the grid which you need.
– Oleg Aug 09 '11 at 11:46 -
is there any way to use these cell values outside the code ? u want to use it as a edit parameter in 'navgrid' – Saad Aug 11 '11 at 05:46
-
1@Saad: look at [here](http://stackoverflow.com/questions/5286562/jqgrid-navgrid-button-calling-asp-net-mvc-view-how/5287994#5287994) – Oleg Aug 11 '11 at 05:48
-
take a look at this scenario : http://stackoverflow.com/questions/7022746/jqgrid-selection-issue-with-duplicates-columns – Saad Aug 11 '11 at 11:39
-
`var grid = $('#UserDetails'); var id = grid.getGridParam('selrow');` I did the same. On `click` event, the above code is invoked, but I get `id` as `null`. What could be the reason for this? – Suhail Gupta Oct 09 '15 at 07:42
-
@SuhailGupta: `null` value of `selrow` parameter means that no row is selected in the grid at the moment. – Oleg Oct 09 '15 at 07:43
-
@Oleg Yes. The code is invoked when the grid `UserDetails` is clicked. `$('#UserDetails').click(function() {...})`Do I need to write a handler for each row? – Suhail Gupta Oct 09 '15 at 07:46
-
@Oleg Could you please have a look at the question : http://stackoverflow.com/questions/33033046/getting-id-as-undefined-when-jqgrid-row-is-clicked – Suhail Gupta Oct 09 '15 at 08:04
-
This is getting a column by name from the selected row. It is not getting which cell is *selected* (Although I am not sure why the OQ would want the value rather than the index...). – sf_jeff Nov 18 '22 at 20:05
You can use in this manner also
var rowId =$("#list").jqGrid('getGridParam','selrow');
var rowData = jQuery("#list").getRowData(rowId);
var colData = rowData['UserId']; // perticuler Column name of jqgrid that you want to access

- 2,647
- 4
- 24
- 38
Just to add, you can also retrieve a jqGrid cell value, based on the rowID plus column index (rather than the Column name):
So, to fetch the value in the forth column (column index # 3) for the row with primary key ID 1234, we could use this:
var rowID = 1234;
var columnIndex = 3;
var cellValue = $("#" + rowID).find('td').eq(columnIndex).text();
Btw, on a completely unrelated topic (but please don't vote me down):
I didn't realise that you can, fairly easily, link text boxes to your jqGrid, so your users can do instant searching, without having to open the Search dialog.
To do this, you need a bit of HTML like this:
<input type="text" name="employeeName" id="employeeName" style="width:250px" />
<!-- This will be my jqGrid control and pager -->
<table id="tblEmployees"></table>
<div id="pager"></div>
And a bit of JavaScript like this:
$("#employeeName").on('change keyup paste', function () {
SearchByEmployeeName();
});
function SearchByEmployeeName()
{
// Fetch the text from our <input> control
var searchString = $("#employeeName").val();
// Prepare to pass a new search filter to our jqGrid
var f = { groupOp: "AND", rules: [] };
// Remember to change the following line to reflect the jqGrid column you want to search for your string in
// In this example, I'm searching through the UserName column.
f.rules.push({ field: "UserName", op: "cn", data: searchString });
var grid = $('#tblEmployees');
grid[0].p.search = f.rules.length > 0;
$.extend(grid[0].p.postData, { filters: JSON.stringify(f) });
grid.trigger("reloadGrid", [{ page: 1 }]);
}
This is a real game-changer for me... it really makes jqGrid much more user friendly.
Users can immediately start typing in their search string, rather than needing to open the Search dialog, remember to change the operator to "contains", then start typing, and close the search dialog again.

- 27,846
- 7
- 149
- 159
Use "selrow" to get the selected row Id
var myGrid = $('#myGridId');
var selectedRowId = myGrid.jqGrid("getGridParam", 'selrow');
and then use getRowData to get the selected row at index selectedRowId.
var selectedRowData = myGrid.getRowData(selectedRowId);
If the multiselect is set to true on jqGrid, then use "selarrrow" to get list of selected rows:
var selectedRowIds = myGrid.jqGrid("getGridParam", 'selarrrow');
Use loop to iterate the list of selected rows:
var selectedRowData;
for(selectedRowIndex = 0; selectedRowIndex < selectedRowIds .length;
selectedRowIds ++) {
selectedRowData = myGrid.getRowData(selectedRowIds[selectedRowIndex]);
}

- 41
- 3
yo have to declarate de vars...
var selectedRowId = $('#list').jqGrid ('getGridParam', 'selrow');
var columnName = $('#list').jqGrid('getCell', selectedRowId, 'columnName');
var nombre_img_articulo = $('#list').jqGrid('getCell', selectedRowId, 'img_articulo');

- 41
- 2
Just Checkout This :
Solution 1 :
In Subgrid Function You have to write following :
var selectid = $(this).jqGrid('getCell', row_id, 'id');
alert(selectid);
Where row_id
is the variable which you define in subgrid as parameter.
And id
is the column name which you want to get value of the cell.
Solution 2 :
If You Get Jqgrid Row Id In alert Then set your primary key id as key:true
In ColModels. So You will get value of your database id in alert. Like this :
{name:"id",index:"id",hidden:true, width:15,key:true, jsonmap:"id"},

- 996
- 1
- 8
- 16