struts 2 在格式化前使用jqGrid获取行数据

struts 2 use jqGrid to get row data before format

我想在加载后获取jGrid 数据。

有些列有格式化程序,但我想在格式化之前获取它们的原始数据。

网格列是:

<sjg:gridColumn name="accountNo" formatter="linkBulider" />
<sjg:gridColumn name="amount" />

我使用下面的js:

var allRowsInGrid = $('#gridtable').jqGrid('getRowData');
for (i = 0; i < allRowsInGrid.length; i++) {
   //For accountNo I get the formmated value 
   allRowsInGrid[i].accountNo;
   //The amount is ok as it is unformated
   allRowsInGrid[i].amount;
}

根据 wiki getRowData 不是 return 来自网格的实际数据。

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

使用 custom formatter 选项格式化单元格内容后,您需要一个取消数据格式的选项。

The question is: What to do if we use a custom formatter function and want to to have the original value back if we use editing or methods getRowData and getCell?

The answer is: You can use your own custom unformatter function to do that. This function can be used in colModel.

此时您可以检查是否可以将 sjg:gridColumn 设置为定义 unformat 函数的属性。很遗憾,您不能根据 TLD 执行此操作。

但是,您可以在加载后修改网格。

$(document).ready(function(){
 $("#gridtable").jqGrid('setColProp', 'accountNo',{
    unformat: unformatFunc
  }).trigger("reloadGrid");
});