element 根據某一個屬性合並列


 

 
          
         

 

  通過 span-method 綁定方法 objectSpanMethod方法
   this.getSpanArr(this.tableData); //this.tableData 指接口取到的數據
 // 2、 因為要合並的行數是不固定的,此函數是實現合並隨意行數的功能
    getSpanArr(data) {
      this.spanArr = [];
      for (var i = 0; i < data.length; i++) {
        if (i === 0) {
          // 如果是第一條記錄(即索引是0的時候),向數組中加入1
          this.spanArr.push(1);
          this.pos = 0;
        } else {
          if (data[i].parentCode === data[i - 1].parentCode) {
            // 如果parentCode相等就累加,並且push 0  這里是根據一樣的parentCode匹配 
            this.spanArr[this.pos] += 1;
            this.spanArr.push(0);
          } else {
            // 不相等push 1
            this.spanArr.push(1);
            this.pos = i;
          }
        }
      }
    },
    // 3、合並行數
    objectSpanMethod({ row, column, rowIndex, columnIndex }) {
      // columnIndex === 0 找到第一列,實現合並隨機出現的行數
      if (columnIndex === 0) {
        const _row = this.spanArr[rowIndex];
        const _col = _row > 0 ? 1 : 0;
        return {
          rowspan: _row,
          colspan: _col
        };
      }
    },

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM