jqGrid Row Object in onSelectRow
Asked Answered
W

3

9

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.

Weller answered 20/10, 2011 at 15:57 Comment(0)
S
11

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.

Schlesinger answered 20/10, 2011 at 21:1 Comment(4)
@SystemParadox: You are welcome! I recommend you additionally examine the getLocalRow method. Look the answer or another one for some small code examples and additional information. The source code of the method is very small and I recommend you to read it too.Schlesinger
I have to admit, I always overlooked it, but the storing the data for later use on the loadComplete is a very valuable functionality. Since I never use datatype : 'local' or loadonce : true. I even wonder why it isn't stored by default in some kind of 'rawdata' property. Anyway thanks for pointing it out Oleg. +1Perforate
@Steven: You are welcome! I recommend to use loadonce: true and small rowNum (the page size) in case if the total number of rows less as 1000 or even 10000. For example the demo uses 4000 rows, 13 columns and 20 rows in a page and another demo display 40000 rows. You can try to sort, page and filter the grid to see the performance.Schlesinger
@Schlesinger : Hi Oleg thanks for the great examples. I'm aware that loading all data at once has only benefits. Unforunately loading data from db (which is beyond my responsibility) takes in many cases too long to load if I request all data. So I send paged queries to the db too.Perforate
B
4

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

Bioclimatology answered 23/5, 2012 at 8:25 Comment(0)
M
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.

Medardas answered 4/12, 2012 at 10:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.