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

<el-table  :span-method="objectSpanMethod" border style="width: 97%" max-height="600" :header-cell-class-name='must' :show-overflow-tooltip="false"></el-table>
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容