I need to get the text and value of a cell in jqGrid that is of edittype='select'
Here's my colModel
{ name: 'ResponsibleId', editable: true, width: 140, sortable: false, formatter: 'select', edittype: 'select', editoptions: { value: ResponsibleList } }
I'm using inline editing and free-jqgrid v4.9.0
When I run var respId = $(gridId).jqGrid('getCell', row_id, "ResponsibleId");
It gives me the right value of the item but I need the text as well.
thanks
I recommend you to get selected option directly. You need only know that jqGrid assign id
on editable fields based on the rule: rowid + "_" + columnName
. So the code which you need will be
var $option = $("#" + $.jgrid.jqID(row_id) + "_ResponsibleId option").filter(":selected");
The $option.text()
will get you the text and $option.val()
gets you the value of currently selected option.
UPDATE: If you need to get the text of the cell which uses formatter: "select"
you can do for example the following:
var $grid = $(gridId),
$tr = $grid.jqGrid("getGridRowById", row_id),
iCol = $grid.jqGrid("getGridParam", "iColByName").ResponsibleId, // or [colname]
$tdData = $.jgrid.getDataFieldOfCell.call($grid[0], $tr, iCol);
alert($tdData.text());
$tdData
will get you jQuery wrapper to <td>
or some internal <span>
of <td>
which holds the data which you require. $tdData.text()
gets you the text from the cell. If the name of column you have in the variable (in colName
for example) then you should use [colName]
instead of .ResponsibleId
.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments