美文网首页
合并单元格

合并单元格

作者: V_Jan | 来源:发表于2020-12-03 13:59 被阅读0次
    codeDiffSpanArr: any[] = []//二维数组,用于存放单元格合并规则
        // position: number= 0//用于存储相同项的开始index
        codeDiffRowspan(colIndex: number, colName: string) {
            console.log("rowspan()被调用:" + colName)
            this.codeDiffSpanArr[colIndex] = []
            let position = 0;
            this.codeDiff.forEach((row, index) => {
                if (index === 0) {
                    this.codeDiffSpanArr[colIndex].push(1)
                    position = 0
                } else {
                    if (this.codeDiff[index][colName] === this.codeDiff[index - 1][colName]) { //当前值和上一条相同时
                        this.codeDiffSpanArr[colIndex][position] += 1
                        this.codeDiffSpanArr[colIndex].push(0)
                    } else {
                        this.codeDiffSpanArr[colIndex].push(1)
                        position = index
                    }
                }
            })
        }
    
        objectSpanMethod(param: { row: any, column: any, rowIndex: number, columnIndex: number }) {
            console.log("objectSpanMethod()被调用")
            if (isEmpty(param.row))
                return
            for (let i = 0; i < 2; i++) { //第一二列适用合并规则
                if (param.columnIndex === i) {
                    const _row = this.codeDiffSpanArr[i][param.rowIndex];
                    const _col = _row > 0 ? 1 : 0;
                    // console.log('第'+rowIndex+'行','第'+i+'列','rowspan:'+_row,'colspan:'+_col)
                    return {
                        rowspan: _row,
                        colspan: _col
                    }
                }
            }
            return
        }
    

    相关文章

      网友评论

          本文标题:合并单元格

          本文链接:https://www.haomeiwen.com/subject/cqysrktx.html