这个在线demo中看,是对比了当前列和上一列的单元格值是否一致,以此决定单元格是否向上向下合并,
你的需求实际上是对比当前单元格左侧所有列的对应单元格值都是否一致,都一致才向上向下合并,因此,可以做如下改写
- RestrictedMergeManager.prototype.getMergedRange = function(p, r, c, clip) {
- if(clip === void 0) {
- clip = true;
- }
- var rng = null;
- rng = new wjGrid.CellRange(r, c);
-
- var pcol = c > 0 ? c - 1 : c;
- var val = p.getCellData(r, c, false);
- var pval = p.getCellData(r, pcol, false);
- var array = [];
- for(let j = 0; j <= c; j++) {
- array.push(j);
- }
- while(
- rng.row > 0 &&
- array.every(
- (col) =>
- p.getCellData(rng.row - 1, col, false) == p.getCellData(rng.row, col, false)
- )
- ) {
- rng.row--;
- }
- while(
- rng.row2 < p.rows.length - 1 &&
- array.every(
- (col) =>
- p.getCellData(rng.row2 + 1, col, false) == p.getCellData(rng.row2, col, false)
- )
- ) {
- rng.row2++;
- }
-
- if(rng.isSingleCell) {
- rng = null;
- }
- return rng;
- };
复制代码 |