Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 386
Cyber Avatar asked Feb 15 '23 10:02

Cyber


1 Answers

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.

like image 174
Oleg Avatar answered Feb 17 '23 01:02

Oleg