0
我是jqGrid的新手,我想以動態方式生成組頭,但它確實有效,getValues('department')語句分析用戶輸入的部門,例如'a,b, c代碼如下:jqGrid組頭問題
function search() {
var startDate = $('#startDate').val();
var endDate = $('#endDate').val();
var department = getValues('department');
var colName = new Array();
var colAttr = new Array();
colName[0] = "日期";
colAttr[0] = "{name:'" + colName[0] + "',sortable:false,align:'center'}"
var length = getLength(department);
for (var i = 1; i < length + 1; i++) {
colName[2 * i - 1] = "諮詢" + i;
colName[2 * i] = "投訴" + i;
colAttr[2 * i - 1] = "{name:'" + colName[2 * i - 1] + "'index:'" + i + "',sortable:false,align:'center'}";
colAttr[2 * i] = "{name:'" + colName[2 * i] + "',sortable:false,align:'center'}";
}
var header = mySplitter(department);
var urlStr = '<%=jspName%>?startDate=' + startDate + '&endDate=' + endDate + '&action=query&department=' + department;
urlStr = encodeURI(urlStr);
jQuery("#dataGrid").clearGridData();
jQuery("#dataGrid").GridUnload();
jQuery("#dataGrid").jqGrid({
url: urlStr,
datatype: "json",
colNames: colName,
colModel: colAttr,
height: 450,
rowNum: 20000, //默認每頁記錄數
rowList: [10, 20, 30], //可選擇的每頁記錄數
pager: '#dataPager',
shrinkToFit: true,
hidegrid: false,
emptyrecords: "暫無數據",
viewrecords: true,
loadonce: true, //自動翻頁
caption: "<%=title%>"
});
jQuery("#dataGrid").jqGrid('navGrid', '#dataPager', {edit: false, add: false, del: false, autowidth: true});
$("#dataGrid").setGridWidth($(window).width() * 0.90);
jQuery("#dataGrid").jqGrid('setGroupHeaders', {
useColSpanStyle: true,
groupHeaders: header
});
}
function mySplitter(str) {
if (str === null) {
return null;
}
var temp;
temp = str.split(",");
var result = new Array();
for (var i = 0; i < temp.length - 1; i++) {
result[i] = "{startColumnName: '" + (i + 1) + "', numberOfColumns: 2, titleText: '" + temp[i] + "'}";
}
return result;
}
function getLength(str) {
if (str === null) {
return 0;
}
var temp = str.split(",");
return temp.length - 1;
}
代碼沒有生成組頭。有人可以幫助我嗎? colModel
陣列的
謝謝你的答案!我會再試一次。 – user2926672