首页 > 其他分享 >使用Element的table合并单元格(按相同项) 多列

使用Element的table合并单元格(按相同项) 多列

时间:2022-08-29 16:14:13浏览次数:61  
标签:index arr spanTwoArr 单元格 Element push table spanOneArr row

methods: {
    tableHeaderColor({ row, column, rowIndex, columnIndex }) {
        if (rowIndex === 0) {
          return "color: #4f81bd;font-weight: bold ;";
        }
     },

    objectSpanMethod8({ row, column, rowIndex, columnIndex }) {
        if (columnIndex === 0) {
          const _row = (this.flitterData(this.saCountAvg ).one)[rowIndex];
          const _col = _row > 0 ? 1 : 0;
          return {
            rowspan: _row,
            colspan: _col
          };
        }
        if (columnIndex === 1) {
          const _row = (this.flitterData(this.saCountAvg ).two)[rowIndex];
          const _col = _row > 0 ? 1 : 0;
          return {
            rowspan: _row,
            colspan: _col
          };
        }
      },


      flitterData(arr) {
        let spanOneArr = [],
          spanTwoArr = [],
          concatOne = 0,
          concatTwo = 0;
        arr.forEach((item, index) => {
          if (index === 0) {
            spanOneArr.push(1);
            spanTwoArr.push(1);
          } else {
            if (item.userId === arr[index - 1].userId) { //第一列需合并相同内容的判断条件
              spanOneArr[concatOne] += 1;
              spanOneArr.push(0);
            } else {
              spanOneArr.push(1);
              concatOne = index;
            }
            if (item.getTime === arr[index - 1].getTime && item.userId === arr[index - 1].userId) {//第二列需合并相同内容的判断条件
              spanTwoArr[concatTwo] += 1;
              spanTwoArr.push(0);
            } else {
              spanTwoArr.push(1);
              concatTwo = index;
            }
          }
        })
        return {
          one: spanOneArr,
          two: spanTwoArr,
        }
      },



}

 

标签:index,arr,spanTwoArr,单元格,Element,push,table,spanOneArr,row
From: https://www.cnblogs.com/porter/p/16636293.html

相关文章