jQuery onSelectRow 中的 jqGrid 行对象

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7838726/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 00:20:14  来源:igfitidea点击:

jqGrid Row Object in onSelectRow

jqueryjqgrid

提问by Amanul Islam Chowdhury

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.

如何在 jqGrid 中选择的行上获取行对象?我需要实际的对象,而不是单元格值。我已经阅读了文档,但找不到可以为我提供行对象的方法。因为我使用自定义格式化程序,所以 cellValue 将不起作用。

回答by Oleg

If you implement custom formatterand want to get the cell value with respect of getCellor getRowDatayou have to implement unformatfunction also.

如果您实现自定义格式化程序并想要获取有关getCellgetRowData的单元格值,您还必须实现unformat功能。

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

不清楚您在“我需要实际对象,而不是单元格值”下的意思。还不清楚datatype您使用哪个,是否使用loadonce: true选项以及是否从服务器加载数据,数据将以哪种格式发布到服务器。

If you use datatype: 'local'or use loadonce: truethe internal dataand _indexparameters will be filled. To get raw data from the grid by rowidyou can use

如果使用datatype: 'local'或使用loadonce: true内部data_index参数将被填充。要从网格中获取原始数据,rowid您可以使用

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: trueand 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 loadCompleteevent handler has one dataparameter 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 onSelectRowevent handler.

如果您不使用datatype: 'local'或仅使用loadonce: true和加载来自服务器的数据,则可以将表示来自服务器响应的数据的对象保存在变量中(在对象中)。该loadComplete事件处理程序有一个data参数,它是从服务器发布的原始数据。因此,您可以将所需的数据保存在一个对象中(在一个映射中,它将通过 rowid 获取 yut 对象)并在onSelectRow事件处理程序中使用它。

回答by SystemParadox

You can use the getInd and getLocalRow methods:

您可以使用 getInd 和 getLocalRow 方法:

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

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

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

回答by quando

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).

使用此功能 -> getInd(rowid,rowcontent)

This method returns the index of the row in the grid table specified by id=rowidwhen 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.

此方法返回id=rowid当 rowcontent 设置为 false(默认)时指定的网格表中的行的索引。如果 rowcontent 设置为 true,则返回条目行对象。如果找不到 rowid,则该函数返回 false。