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

匿名 (未验证) 提交于 2019-12-03 03:11:02

问题:

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,

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.

But i also need name2,name3 and name4 data from the selected column to generate second Report.

Is it possible in JqGrid.

Any help is appreciated.

回答1:

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.

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.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!