user2710638
user2710638

Reputation: 115

Get Grid Column value from Jquery

I tried to get column values from JqGrid. But it not possible. Any one can help is pleasure.

var age = $("#list").find(columnName).html();

This shows as Undefined..

Upvotes: 2

Views: 19971

Answers (2)

Oleg
Oleg

Reputation: 222017

I would recommend you to use getCol method (for example in the simplest form of usage: $("#list").jqGrid("getCol", "columnName")). It allows you to get an array of values from the specified column of the grid or to get an array of objects with id and value properties. See the documentation for more details.

Upvotes: 3

Yagnesh Agola
Yagnesh Agola

Reputation: 4657

You need to get the id of the seleted row first, use that rowId in the to getCell that will use that id to get the value of the cell for you.

The code looks like this:

var myGrid = $('#list');
var rowID = myGrid.jqGrid ('getGridParam', 'selrow');
var cellVal = myGrid.jqGrid ('getCell', rowID, 'colName');

Where colName is the name of column for which you want to find value for that, which you gave to your column in the colModel.

If you need more than one columns value than you can get whole row data based on rowID and get column value from it using column name as shown below :

var row = myGrid.jqGrid ('getRowData', rowID); // This will return whole row data (or all columns value) 
var columnVal = row["ColumnName"]; // ColumnName is again name of column define in colModel array.  

May this help you.

Upvotes: 2

Related Questions