在上面的代码attrSetting
中被调用。如果我将其更改为{"name":"A", "index":"0", "cellattr":attrSetting}
. 它运行良好。所以我该怎么做?cellattr 将其视为字符串而不是函数。
var gridData = {"list":[{"A":"abc", "B":"def", "C":"IRIS", "D":"Testing","E":"17-12- 2012","F":"Test", "attr":{"A":{"rowspan": 3}}},{"A":"abc", "B":"def", "C":"IRIS", "D":"Testing","E":"17-12-2012","F":"Test", "attr":{"A":{"display":"none"}}},{"A":"abc", "B":"def", "C":"IRIS", "D":"Testing","E":"17-12-2012","F":"Test", "attr":{"A":{"display":"none"}}}]};
$(document).ready(function(){
prepareGrid();
});
prepareGrid = function(colModel) {
$("#grid").jqGrid({
datatype : 'local',
contentType : 'application/json',
data : gridData.list,
loadtext : "Loading...",
colNames : ['TB Element','GL Element', 'Company Name', 'Status', 'Date', 'User'],
colModel : [
{"name":"A", "index":"0", "cellattr":"attrSetting" },
{name:"B", index:1 },
{name:"C", index:2},
{name:"D", index:3},
{name:"E", index:4},
{name:"F", index:5}
],
width : '500px',
height : '200px',
rownumWidth : 30,
scrollrows : true,
shrinkToFit : false,
rownumbers : true,
viewrecords : true,
});
};
function attrSetting(rowId, val, rawObject, cm) {
var attr = rawObject.attr[cm.name], result;
if (attr.rowspan) {
result = ' rowspan=' + '"' + attr.rowspan + '"';
} else if (attr.display) {
result = ' style="display:' + attr.display + '"';
}
return result;
};