javascript JqG​​rid:如何从 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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 18:39:47  来源:igfitidea点击:

JqGrid: How to get all column values from onCellSelect event?

javascriptjqgrid

提问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 getCellor getRowDatato get the data from the row based on rowid. If you use datatype: "local"or if you use loadonce: trueoption in the grid #Report1then you can use getLocalRowwhich have some advantages over getRowData, but works only if the data are saved locally inside of internal dataparameter. The parameter will be filled only if datatypeis not "json"or "xml"or if it's "json"or "xml", but loadonce: trueoption are used.

您可以使用getCellgetRowData从基于 的行中获取数据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 getLocalRowcould have some advantages (including performance advantage), but you should verify whether it works together with datatypeand loadoncewhich you use in the grid #Report1.

的使用getLocalRow可能有一些优势(包括性能优势),但您应该验证它是否与网格一起使用datatype以及loadonce您在网格中使用了哪些#Report1