jQuery 如何在 JQGrid 中获取单元格值?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2573710/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get a cell value in JQGrid?
提问by dev
How to get a cell value in JQGrid?
如何在 JQGrid 中获取单元格值?
If I use the following syntax –
如果我使用以下语法 –
var ret = jQuery("#MyGrid").jqGrid('getRowData', id);
ret = ret.ProductId;
it returns the following HTML.
它返回以下 HTML。
'input class="editable" name=" ProductId " id="0_ ProductId " style="width: 98%;" type="text"'
I actually need the value of the cell.
我实际上需要单元格的值。
Thanks. Dev
谢谢。开发
回答by HomeSlice
If you only need the value of a cell that has already been saved, you can get it with this
如果你只需要一个已经保存的单元格的值,你可以用这个来获取
$('#myTable').jqGrid('getCell',row_id,'column_name');
回答by Justin Ethier
If you try to get the value of a row while it is being edited, you will retrieve markup (as in your example), instead of the actual value. To quote the jqGrid Documentation for getRowData:
如果您在编辑时尝试获取行的值,您将检索标记(如您的示例中所示),而不是实际值。引用getRowData 的 jqGrid 文档:
Do not use this method when you editing the row or cell. This will return the cell content and not the actual value of the input element
编辑行或单元格时不要使用此方法。这将返回单元格内容而不是输入元素的实际值
The best way around this is to save your row data before calling getRowData
, although alternatively if that is not an option you will have to parse the markup yourself. Which actually is not thathard to do in jQuery, but is still a pain.
解决此问题的最佳方法是在调用 之前保存您的行数据getRowData
,但如果这不是一个选项,您将不得不自己解析标记。这实际上是不是说很难在jQuery的做,但仍是一种痛苦。
回答by Md. Sajedul Karim
You have to follow steps :
您必须按照以下步骤操作:
Read all dataIDs from grid:
从 grid 读取所有数据 ID:
var dataIDs = jQuery("#MY_GRID").getDataIDs();
You can iterate on grid based on ID list. Then you will get row using dataID. When your entire row get done then you can get the cell value.
您可以根据 ID 列表在网格上迭代。然后您将使用 dataID 获取行。当您的整行完成后,您就可以获得单元格值。
Here is the sample working code
这是示例工作代码
for(i = 0; i < dataIDs.length; i++)
{
var rowData = jQuery("#MY_GRID").jqGrid ('getRowData', dataIDs[i]);
console.log(rowData);
var COLL_1_VALUE = $('#MY_GRID').jqGrid('getCell', dataIDs[i], 'COLL_1');
var COLL_2_VALUE = $('#MY_GRID').jqGrid('getCell', dataIDs[i], 'COLL_2');
console.log(COLL_1_VALUE);
console.log(COLL_2_VALUE);
}