I have dynamically generated jqgrid with datatype "jsonstring". Seems .jqGrid('setFrozenColumns'); not working properly. Only Headers are freezing not the actual data rows. When i sort the grid frozen column working. but it break the layout.
below is my implementation
$.ajax({
url: myUrl,
type: 'POST',
data: { issueDate:issueDate },
success: function (result) {
var i;
var cm;
var colModels = result.Json.colModels;
var colNames = result.Json.colNames;
var coldata = result.Json.data.options;
for (i = 0; i < colModels.length; i++) {
cm = colModels[i];
if (cm.hasOwnProperty("formatter")) {
cm.formatter = functionsMapping[cm.formatter];
}
}
$("#ObserationSummarytable").jqGrid({
datatype: 'jsonstring',
datastr: coldata,
colNames: colNames,
colModel: colModels,
jsonReader: {
root: 'rows',
repeatitems: false
},
gridview: true,
rowNum: 50,
width: 1200,
height: 500,
loadtext: "Loading.....",
hoverrows: false,
autoencode: true,
ignoreCase: true,
scrollerbar: true,
rowList: [50, 100, 150],
viewrecords: true,
autowidth: true,
shrinkToFit: false,
forceFit: true,
pager: $('#ObserationSummarypager'),
loadonce: true,
gridComplete: LoadComplete
}).jqGrid('setFrozenColumns');
Generated colmodel
[{"name":"District", "width":80, "align":"left", "sortable": true,"formatter":"ShowGraphlink","frozen": true },{"name":"StationName","width":150, "align":"left", "sortable": true,"formatter":"ShowGraphlink","frozen": true },{"name":"FDL", "width":40, "align":"center", "sortable": true ,"formatter":"FormatFDL" ,"frozen": true },{"name":"DataType", "width":60, "align":"left", "sortable": false,"formatter":"FormatDataType","frozen": true },{"name":"AWDValue","hidden": true ,"frozen": true },{"name":"08:44","width":40, "align":"center","title":false,"sortable": false,"formatter":"FormatCellValues"},{"name":"08:36","width":40, "align":"center","title":false,"sortable": false,"formatter":"FormatCellValues"},{"name":"08:14","width":40, "align":"center","title":false,"sortable": false,"formatter":"FormatCellValues"},{"name":"08:06","width":40, "align":"center","title":false,"sortable": false,"formatter":"FormatCellValues"},{"name":"07:44","width":40, "align":"center","title":false,"sortable": false,"formatter":"FormatCellValues"},{"name":"07:36","width":40, "align":"center","title":false,"sortable": false,"formatter":"FormatCellValues"},{"name":"07:14","width":40, "align":"center","title":false,"sortable": false,"formatter":"FormatCellValues"},{"name":"07:06","width":40, "align":"center","title":false,"sortable": false,"formatter":"FormatCellValues"},{"name":"06:44","width":40, "align":"center","title":false,"sortable": false,"formatter":"FormatCellValues"}]
Load complete function
function LoadComplete() {
var gridRowCount = $('#ObserationSummarytable').getGridParam('records');
if (gridRowCount == null || gridRowCount == 0) // are there any records?
{
$("#divNoRecord").show();
$("#divSummaryGrid").hide();
} else {
$("#divNoRecord").hide();
$("#divSummaryGrid").show();
}
}
function mapping
var functionsMapping = {
// here we define the implementations of the custom formatter which we use
"ShowGraphlink": function (cellValue, opts, rowObject) {
return "link";
},
"FormatCellValues": function (cellValue, opts, rowObject) {
return cellHtml;
},
"FormatDataType": function (cellValue, opts, rowObject) {
return 'some html';
},
"FormatFDL": function (cellValue, opts, rowObject) {
return cellValue;
}
};