easyui 合并单元格(个人笔记)
程序员文章站
2022-07-13 14:28:11
...
方法是判断数据是否与上一条数据相等
onLoadSuccess:function(data){
if (data.rows.length > 0) {
//调用mergeCellsByField()合并单元格
//mergeCellsByField("warehouse", "salesOrder,billCode");此方法同样能合并单元格
var mark =1;
for(var i=1;i<data.rows.length;i++){
var row = $(this).datagrid('getData').rows[i];
var row1 = $(this).datagrid('getData').rows[i-1];
var salesOrder = row.salesOrder;
var salesOrder1 = row1.salesOrder;
var billCode = row.billCode;
var billCode1 = row.billCode;
if(salesOrder==salesOrder1&&billCode==billCode1){
mark +=1;
$(this).datagrid('mergeCells',{
index:i+1-mark,
field:'salesOrder',
rowspan:mark
});
$(this).datagrid('mergeCells',{
index:i+1-mark,
field:'billCode',
rowspan:mark
});
}else{
mark=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
});
tmpA = 1;
}
PerTxt = CurTxt;
}
}
}
上一篇: 取色器
下一篇: element合并单元格