function MergeCells(seletor, rows, fields) {
if(rows == null || rows.length == 0 || fields == null || fields.length == 0) {
return;
}
var rowCount = 1;
var index = 0;
for(var i = 0; i < rows.length; i++) {
var row = rows[i];
if(i > 0) {
var flag = true;
for(var z = 0; z < fields.length; z++) {
if(rows[i - 1][fields[z]] != row[fields[z]]) {
flag = false;
break;
}
}
if(flag) {
rowCount += 1;
}
if(!flag || (rowCount > 1 && i == rows.length - 1)) {
for(var j = 0; j < fields.length; j++) {
$(seletor).datagrid("mergeCells", {
index: index,
field: fields[j],
rowspan: rowCount,
colspan: 1
});
}
rowCount = 1;
index = i;
}
}
}
}
用法
onLoadSuccess: function(data) {
var rows =data.rows;
MergeCells("#dg",rows,feilds);
}