jqGrid获取当前选中行的数据

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/">

你可能感兴趣的:(jqGrid)