Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jqGrid Row Object in onSelectRow

Tags:

jquery

jqgrid

How do I get row object on row selected in jqGrid? I need the actual object, not the cellvalue. I have gone through the documentation but could not find a method that will give me the row object. since I use custom formatters, the cellValue will not work.

like image 552
Amanul Islam Chowdhury Avatar asked Oct 20 '11 15:10

Amanul Islam Chowdhury


2 Answers

If you implement custom formatter and want to get the cell value with respect of getCell or getRowData you have to implement unformat function also.

It is not clear what you mean under "I need the actual object, not the cellvalue". It is also unclear which datatype you use, whether you use loadonce: true option or not and if you load the data from the server in which format the data will be posted to the server.

If you use datatype: 'local' or use loadonce: true the internal data and _index parameters will be filled. To get raw data from the grid by rowid you can use

var rowData = this.p.data[this.p._index[rowid]]

or

var grid = $(this),
    localdata = grid.jqGrid('getGridParam', 'data'),
    indexes = grid.jqGrid('getGridParam', '_index'),
    rowData = localdata[indexes[rowid]];

If you don't use datatype: 'local' or use loadonce: true and load the data from the server only you can save the object represented the data from the server response in a variable (in an object). The loadComplete event handler has one data parameter which is the raw data posted from the server. So you are able to save the data which you need in a object (in a map which will get yut object by rowid) and use it inside of the onSelectRow event handler.

like image 52
Oleg Avatar answered Nov 07 '22 14:11

Oleg


You can use the getInd and getLocalRow methods:

onSelectRow: function(rowid) {
    var row = $(this).getLocalRow(rowid);
    // do something with row
}

http://www.trirand.com/jqgridwiki/doku.php?id=wiki:methods

like image 37
SystemParadox Avatar answered Nov 07 '22 14:11

SystemParadox