element table 合并单元格

返回示例

js

            // 合并单元格
            merge(data) {
                        //data表格数据
                this.spanArr = [];
                for (var i = 0; i < data.length; i++) {
                    if (i === 0) {
                        this.spanArr.push(1);
                        this.pos = 0;
                    } else {
                        if (data[i].color_name) { // 判断当前元素与上一个元素是否相同
                            if (data[i].color_name === data[i - 1].color_name) {
                                this.spanArr[this.pos] += 1;
                                this.spanArr.push(0);
                            } else {
                                this.spanArr.push(1);
                                this.pos = i;
                            }
                        } else {
                            this.spanArr.push(1);
                            this.pos = i;
                        }

                    }
                    
                }
            },

                          // 合并单元格
            objectSpanMethod({
                row,
                column,
                rowIndex,
                columnIndex
            }) {
                if (columnIndex === 0 || columnIndex === 2) {
                    const _row = this.spanArr[rowIndex];
                    const _col = _row > 0 ? 1 : 0;
                    return {
                        rowspan: _row,
                        colspan: _col
                    };
                }
            },

html


你可能感兴趣的:(element table 合并单元格)