$obj = $("#configQueryGrid");
$obj.datagrid({
loadMsg: '數據加載中請稍後……',
url: '/getData',
nowrap: true,//設置爲true 有利於提高性能
method: 'post',
pagination: true,//分頁顯示
/* fitColumns: true,//自動適應寬度*/
autoRowHeight: true,//自動行高度
rownumbers: true,//顯示行號
pagePosition: 'bottom',
toolbar: '#tb',
pageNumber: 1,//初始化頁面數量
pageSize: 10,//初始化顯示條數
pageList: [10, 20, 50, 100],//分頁列表
border: true,
dateFormat: "yyyy-MM-dd",
idField: 'id',//字段標識
striped: true,
columns: [[
{field: 'id', checkbox: 'true'},
{
field: 'aa',
title: 'aa',
width: 130
},
{
field: 'bb',
title: "bb",
width: 100,
},
{
field: 'cc',
title: "cc,
width: 380
}
]
],
queryParams: params, //參數
onLoadSuccess: function (data) {
//表格加載完成執行,合併單元格
mergeCellsByField("configQueryGrid", "aa,bb");
},
onCheck:onCheck,
onUncheck:onUncheck
})
}
//合併單元格後複選框也進行了合併,選中複選框合併行全部選中
var rs = -1;
function onCheck(index, row) {
if (rs == -1) {
rs = index;
var rbs = row.bs;
var rows = $("#configQueryGrid").datagrid("getRows");
// console.info(rows);
for (var z = 0; z < rows.length; z++) {
if (rbs === rows[z].bs) {
$("#configQueryGrid").datagrid("checkRow", z);
}
}
rs = -1
}
}
function onUncheck(index, row) {
if (rs == -1) {
rs = index;
var rbs = row.bs;
var rows = $("#configQueryGrid").datagrid("getRows");
for (var i = 0; i < rows.length; i++) {
if (rbs === rows[i].bs) {
$("#configQueryGrid").datagrid("uncheckRow", i);
}
}
rs = -1
}
}
//合併單元格
function mergeCellsByField(tableID, colList) {
var ColArray = colList.split(",");
var tTable = $("#" + tableID);
var TableRowCnts = tTable.datagrid("getRows").length;
var tmpA;
var tmpB;
var PerTxt = "";
var CurTxt = "";
var alertStr = "";
for (j = ColArray.length - 1; j >= 0; j--) {
PerTxt = "";
tmpA = 1;
tmpB = 0;
for (i = 0; i <= TableRowCnts; i++) {
if (i == TableRowCnts) {
CurTxt = "";
} else {
CurTxt = tTable.datagrid("getRows")[i][ColArray[j]];
}
if (PerTxt == CurTxt) {
tmpA += 1;
} else {
tmpB += tmpA;
tTable.datagrid("mergeCells", {
index: i - tmpA,
field: ColArray[j],
//合併字段
rowspan: tmpA,
colspan: null
});
tTable.datagrid("mergeCells", {
index: i - tmpA,
field:'id',
//合併字段
rowspan: tmpA,
colspan: null
});
tmpA = 1;
}
PerTxt = CurTxt;
}
}
}