EasyUI Datagrid 动态合并单元格
程序员文章站
2022-03-11 16:34:43
...
/**
* EasyUI DataGrid根据字段动态合并单元格
* @param fldList 要合并table的id
* @param fldList 要合并的列,用逗号分隔(例如:"name,department,office");
*/
function MergeCells(tableID, fldList) {
var Arr = fldList.split(",");
var dg = $('#' + tableID);
var fldName;
var RowCount = dg.datagrid("getRows").length;
var span;
var PerValue = "";
var CurValue = "";
var length = Arr.length - 1;
for (i = length; i >= 0; i--) {
fldName = Arr[i];
PerValue = "";
span = 1;
for (row = 0; row <= RowCount; row++) {
if (row == RowCount) {
CurValue = "";
}
else {
CurValue = dg.datagrid("getRows")[row][fldName];
}
if (PerValue == CurValue) {
span += 1;
}
else {
var index = row - span;
dg.datagrid('mergeCells', {
index: index,
field: fldName,
rowspan: span,
colspan: null
});
span = 1;
PerValue = CurValue;
}
}
}
}
//调用方法
$('#datagridDiv').datagrid({
//…………获取数据成功后回调
onLoadSuccess:function(){
MergeCells("datagridDiv","TYPE");//要合并的列,多个字段用逗号分隔
}
});
上一篇: 使用Etag来实现前端缓存
下一篇: jquery 动态合并单元格列