I have a jqgrid with dynamic data binding, and required to set a custom title for each cell. I applied the method described in the solution for JQGrid with dynamic column: cellattr does not work
but it does not work. My code is as follows.
The action method that sets the colModel:
var result = new {
Json = new {
colNames = new[] { "T1", "T2" },
colModels = new[] {
new { index = "T1", label = "T1", name = "T1",
width = 100, cellattr = "customTitle",
editable = true, strtooltip = "A0" },
new { index = "T2", label = "T2", name = "T2",
width = 100, cellattr = "customTitle",
editable = true, strtooltip = "A1"
}
},
data = ......................
$.ajax({
url: '/Client/PatientListing/GetTestData',
type: 'POST',
data: {},
success: function (result) {
var colModels = result.Json.colModels;
var colNames = result.Json.colNames;
var data = result.Json.data.options;
jQuery.each(colModels, function (index, value) {
debugger;
cm = value;
if (cm.hasOwnProperty("cellattr") &&
functionsMapping.hasOwnProperty(cm.cellattr)) {
cm.cellattr = functionsMapping[cm.cellattr];
}
});
var functionsMapping = {
"customTitle": function (rowId, val, rawObject) {
return 'title="' + rawObject.T1 + ' (' + rawObject.T2 + ')"';
}
};