Within the given code snippet, the function attrSetting
is invoked. However, when I modify it to
{"name":"A", "index":"0", "cellattr":attrSetting}
, the code executes smoothly. But here lies the issue - cellattr interprets it as a string rather than a function.
let 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();
});
function prepareGrid(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) {
let attr = rawObject.attr[cm.name], result;
if (attr.rowspan) {
result = ' rowspan=' + '"' + attr.rowspan + '"';
} else if (attr.display) {
result = ' style="display:' + attr.display + '"';
}
return result;
};