javascript JqGrid:如何从 onCellSelect 事件中获取所有列值?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20512859/
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
JqGrid: How to get all column values from onCellSelect event?
提问by Cyber
I am developing an ASP.NET mvc project which uses JqGrid for generating report. For report generation i am generating 2 different reports . Second report will be generated based on the values of First report. For getting column values i am using OnCellSelect event of JqGrid,
我正在开发一个使用 JqGrid 生成报告的 ASP.NET mvc 项目。对于报告生成,我正在生成 2 个不同的报告。将根据第一个报告的值生成第二个报告。为了获取列值,我使用 JqGrid 的 OnCellSelect 事件,
Event:
事件:
$('#Report1').jqGrid({
...
..
colNames: ['name1','name2','name3','name4','name5','name6','name7'],
colModel: [
{....},
{ ... },
{ ...},
{...},
{ ...},
{ ...},
{ ... }
],
jsonReader: {
root: 'DD_data',
id: 'name1',
repeatitems: false
},
pager: $('#pager'),
//Event fires when clicked on name7
onCellSelect: function (rowid, index, contents, event) {
//Code for generating Second Report based on First report data//
$('#Report2').jqGrid({
...
...
});
}
});
Here in Cell Select event i am only getting rowid , my key , and selected cell content.
在 Cell Select 事件中,我只得到 rowid 、 my key 和选定的单元格内容。
But i also need name2,name3 and name4 data from the selected column to generate second Report.
但我还需要来自所选列的 name2、name3 和 name4 数据来生成第二个报告。
Is it possible in JqGrid.
在 JqGrid 中可能吗?
Any help is appreciated.
任何帮助表示赞赏。
回答by Oleg
You can use getCell
or getRowData
to get the data from the row based on rowid
. If you use datatype: "local"
or if you use loadonce: true
option in the grid #Report1
then you can use getLocalRow
which have some advantages over getRowData
, but works only if the data are saved locally inside of internal data
parameter. The parameter will be filled only if datatype
is not "json"
or "xml"
or if it's "json"
or "xml"
, but loadonce: true
option are used.
您可以使用getCell
或getRowData
从基于 的行中获取数据rowid
。如果您在网格中使用datatype: "local"
或使用loadonce: true
选项,#Report1
那么您可以使用getLocalRow
它比 具有一些优势getRowData
,但只有在数据本地保存在内部data
参数内时才有效。仅当datatype
不是"json"
or"xml"
或如果它是"json"
or 时才会填充参数"xml"
,但使用了loadonce: true
选项。
The simplest code which you can use would be
您可以使用的最简单的代码是
onCellSelect: function (rowid) {
var rowData = $(this).jqGrid("getRowData", rowid);
// now you can use rowData.name2, rowData.name3, rowData.name4 ,...
}
Usage of getLocalRow
could have some advantages (including performance advantage), but you should verify whether it works together with datatype
and loadonce
which you use in the grid #Report1
.
的使用getLocalRow
可能有一些优势(包括性能优势),但您应该验证它是否与网格一起使用datatype
以及loadonce
您在网格中使用了哪些#Report1
。