表格根據前一列對應關係合并單元格

博客记录了Java开发中方法封装的相关内容,以及在接口数据返回时的调用情况,属于个人开发记录,聚焦于Java技术应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  // 表格合并算法
        tableMergeMethod(columnArr, tableData) {
            let column = {};
            let position = 0;
            let lastColumnName = null;
            // 遍历合并的列数据
            columnArr.forEach((prop) => {
                column[prop] = [];
                let lastColumn = lastColumnName === null ? null : column[lastColumnName];
                //  遍历合并的行数据
                tableData.forEach((row, rowIndex) => {
                    // 第N列第一行
                    column[prop][rowIndex] = [1, 1];
                    if (rowIndex === 0 || (lastColumn != null && lastColumn[rowIndex][0] > 0)) {
                        // 记录当前行号
                        position = rowIndex;
                    } else if (row[prop] === tableData[rowIndex - 1][prop]) {
                        // 当前行数据等于上一行,根据记录的行号,计算需要合并几行。
                        column[prop][position][0] += 1;
                        // 当前行 隐藏不显示
                        column[prop][rowIndex][0] = 0;
                    } else {
                        // 不相等之后,重置记录行号
                        position = rowIndex;
                    }
                });
                lastColumnName = prop;
            });
            return column;
        },

 方法封裝  

接口數據返回時調用

        // 獲取表格數據
        getTableList() {
            getAmountMaterialList(this.queryParams).then(res => {
                this.tableData = res.data
                let columnArr = ['deptName', 'recordContent', 'productionUnitName']
                this.mergeArr = this.tableMergeMethod(columnArr, this.tableData);
            })
        },
        // 合并單元格
        arraySpanMethod({ row, column, rowIndex, columnIndex }) {
            let arr = this.mergeArr[column.property] || [];
            if (arr.length) return arr[rowIndex];
            else[1, 1];
        },

個人記錄

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值