jqGrid获取当前选中行的数据

本文介绍了jqGrid获取当前选中行数据的两种方法:getLocalRow(推荐使用)和getRowData。getLocalRow从本地数据数组中获取行数据,而getRowData返回指定rowid的数据,但在编辑时会返回cell内容而非实际值。注意,getRowData在大量数据时可能影响性能,并且如果没有设置rowid,将返回整个网格数据。在使用包含checkbox的自定义列时,使用getRowData会返回checkbox的自定义内容。

1. getLocalRow (推荐使用)

Return the row data from the local array stored in data parameter when
the datatype is local

根据官方说明,当jqGri的datatypelocal时,getLocalRow从data参数中,存储在本地的数组中获取行数据.

$("#grid").getLocalRow(rowid);

2. getRowData

Returns an array with data of the requested id = rowid. The returned array is of type name:value, where the name is a name from colModel and the value from the associated column in that row. It returns an empty array if the rowid can not be found.

  1. Do not use this method when you are editing the row or cell. This will return the cell content and not the actuall value of the input element.
  2. the performance of this method becomes an issue. Do not use this method in the body of “for” and “when”. (When calling this method, it will calculates the row datas one time.)
    If the rowid is not set the method return all the data from the grid in array

值得注意的是上面的两点:
1) 请不要在编辑行或者列时使用此方法,这个方法将会返回input元素的html内容而不是所期待的值.
2)不要在 for循环或者when 中使用此方法,性能上会有所影响,数据多时可能会导致很慢.
举个实际的例子,当你在使用有checkbox的自定义时使用此方法,那么返回的对象中,checkbox相关的内容将是你的自定义内容:

<input type="checkbox" name="gridChks" class="gridChks" onclick="xxx" checked="true/">
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值