jqGrid Row Object in onSelectRow

2020-08-26 05:46发布

问题:

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.

回答1:

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.



回答2:

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



回答3:

in my project:

ondblClickRow : function(rowid,iRow,iCol,e) {
    $($("#completeDetail").getInd(rowid,true)).find(":first").click();
}

This would solve the row increase not find looking for the row

use this function -> getInd(rowid,rowcontent).

This method returns the index of the row in the grid table specified by id=rowid when rowcontent set to false (default). If rowcontent is set to true, it returns the entry row object. If the rowid can not be found, the function returns false.



标签: jquery jqgrid