<table id="tableID" class="easyui-datagrid" nowrap="false"
data-options="
border:false,
url:'xxxxxxxxxxxxxxxxxxxx.do',
fitColumns:true,
striped:true,
singleSelect:true,
onLoadSuccess: loadSuccess">
<thead>
<tr>
<th data-options="field:'ID',hidden:true" align="center">ID</th>
<th data-options="field:'FRIST',width:20," align="center">一级</th>
<th data-options="field:'SECOND',width:60" align="left">二级</th>
</tr>
</thead>
</table>function loadSuccess(data){
if (data.rows.length > 0) {
mergeCellsByField("t
ableID", "FRIST");
}
}
/**
* EasyUI DataGrid根据字段动态合并单元格
* 参数 tableID 要合并table的id
* 参数 colList 要合并的列,用逗号分隔(例如:"name,department,office");
*/
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", { //根据ColArray[j]进行合并
index: i - tmpA,
field: "Ideparture",
rowspan: tmpA,
colspan: null
});
tmpA = 1;
}
PerTxt = CurTxt;
}
}
}
转载请注明原文地址: https://ju.6miu.com/read-1122.html