其他分享
首页 > 其他分享> > el-table 行合并 span-method 方法封装

el-table 行合并 span-method 方法封装

作者:互联网

getspan({ row, column, rowIndex, columnIndex }) {
                var getSpanCount = function (dataItems, index, condition, isStart) {
                    if (index < dataItems.length
                        && (index == 0 || isStart || condition(dataItems[index - 1], dataItems[index])))
                        return 1 + getSpanCount(dataItems, index + 1, condition, false);
                    return 0;
                };
                
                var getRowSpanCount = function (rowIndex, dataItems, condition) {
                    if (rowIndex == 0 || !condition(dataItems[rowIndex - 1], dataItems[rowIndex])) {
                        return getSpanCount(dataItems, rowIndex, condition, true);
                    }
                    return 0;
                };

                if (columnIndex == 0) {
                    return { rowspan: getRowSpanCount(rowIndex, this.result, (x, y) => x.checkTypeId == y.checkTypeId), colspan: 1 };
                }

                return { rowspan: 1, colspan: 1 }
            }

this.result 为 el-table 绑定的数据集, 表格多行合并的条件是 x.checkTypeId == y.checkTypeId

只替换上图中三处红色地方的代码,即可实现行合并。

标签:el,span,index,rowIndex,return,checkTypeId,table,dataItems,condition
来源: https://www.cnblogs.com/nanfei/p/16082877.html