采用分治思想,从上到下,从左至右,递归合并
function initMerge(data){
if (data.length<=0)return;
let propertyNames=['p1','p1'];
treeMerge(data,propertyNames,0,0,data.length-1);
}
function treeMerge(data,propertyNames,level,start,end){
if (level>=propertyNames.length)return;
let propertyName=propertyNames[level];
let preValue=data[start][propertyName];
let i = start;
for (;i <= end; i++) {
if (data[i][propertyName]!==preValue){
$('#dgName').datagrid('mergeCells',{
index: start,rowspan: i-start,field:propertyName});
treeMerge(data,propertyNames,level+1,start,i-1);
treeMerge(data,propertyNames,level,i,end);
return;
}
}
$('#dgName').datagrid('mergeCells',{
index: start,rowspan: i-start,field:propertyName});
treeMerge(data,propertyNames,level+1,start,end);
}