我已经动态生成了数据类型为“jsonstring”的jqgrid。似乎 .jqGrid('setFrozenColumns'); 不能正常工作。只有标题被冻结而不是实际的数据行。当我对网格冻结列进行排序时。但它打破了布局。
下面是我的实现
$.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');
生成的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"}]
加载完整函数
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();
}
}
功能映射
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;
}
};