我建议你使用beforeProcessing
回调函数使用简单,功能强大。例如,如果您从服务器获取数据标准 JSON 格式 http://www.trirand.com/jqgridwiki/doku.php?id=wiki%3aretrieving_data#json_data
{
"total": "xxx",
"page": "yyy",
"records": "zzz",
"rows" : [
{"id": "1", "cell": ["cell11", "null", "cell13"]},
{"id": "2", "cell": ["cell21", "cell22", null]},
...
]
}
你可以做类似下面的事情
beforeProcessing: function (data) {
var rows = data.rows, cRows = rows.length, row, iRow, cCol, iCol, cell;
for (iRow = 0; iRow < cRows; iRow++) {
row = rows[iRow].cell;
for (iCol = 0, cCol = row.length; iCol < cCol; iCol++) {
cell = row[iCol];
if (cell === null || cell === "null") {
row[iCol] = "Not Applicable";
}
}
}
}
可以修改服务器返回的数据的方式before数据将由 jqGrid 处理。