隐藏列只是一个具有 CSS 样式display: none 的列。您不能在<td>...</td> 内的 HTML 页面上放置对象。所以对象会通过调用toString方法自动转换成字符串。
您真正需要的是在某处保存对象(例如数组)。当用户稍后选择一行网格时,将调用回调onSelectRow。回调将 rowid 作为参数。所以最好的办法是通过 rowids 将您的自定义信息保存为字典(对象)。
其中一个选项将不是在服务器响应的rows 部分内部发送附加信息,而是在userdata 内部发送。例如,您当前尝试以以下格式发送数据
{
"page": 1
"total": 7
"records": 123
"rows": [
{"id": 10, "cell": ["cell11", "cell12", "cell13", [1, 2, 3]]}
{"id": 20, "cell": ["cell11", "cell12", "cell13", [4, 5, 6]]},
...
{"id": 90, "cell": ["cell11", "cell12", "cell13", [9, 8, 7]]}
]
}
您可以将服务器响应修改为
{
"page": 1
"total": 7
"records": 123
"rows": [
{"id": 10, "cell": ["cell11", "cell12", "cell13", [1, 2, 3]]}
{"id": 20, "cell": ["cell11", "cell12", "cell13", [4, 5, 6]]},
...
{"id": 90, "cell": ["cell11", "cell12", "cell13", [9, 8, 7]]}
],
"userdata": {
"10": [1, 2, 3],
"20": [4, 5, 6],
...
"90": [9, 8, 7]
}
}
如果userdata部分将被jqGrid自动保存在内部参数userData中(注意JSON数据中“userdata”中使用大小写和"userData"作为参数)。
现在您可以通过以下方式在任何回调中获取自定义数据:
onSelectRow: function (rowid) {
var custom = $(this).jqGrid("getGridParam", "userData");
// custom[rowid] is the data from userdata like [4, 5, 6]
}
如果您无法修改服务器响应,您可以将自定义数据移动到 userdata 回调中的 beforeProcessing 部分。有关此类代码的示例,请参见 the answer。