vue+element table合並相同行


       getSpanArr (data) {
            console.log(data)//從后台獲取的數據
            this.spanArr = []
            this.spanCodeArr = []
            for (var i = 0; i < data.length; i++) {
              if (i === 0) {
                //如果是第一條記錄(即索引是0的時候),向數組中加入1
                this.spanArr.push(1)
                this.spanCodeArr.push(1);
                this.pos = 0
                this.codePos = 0
              } else {
                if (data[i].areaName === data[i-1].areaName) {
                  //如果areaName相等就累加,並且push 0
                  this.spanArr[this.pos] += 1
                  this.spanArr.push(0)
                } else {
                  //不相等push 1
                  this.spanArr.push(1)
                  this.pos = i
                }

                if (data[i].deptCode === data[i-1].deptCode) {
                  //如果deptCode相等就累加,並且push 0
                  this.spanCodeArr[this.codePos] += 1
                  this.spanCodeArr.push(0)
                } else {
                  //不相等push 1
                  this.spanCodeArr.push(1)
                  this.codePos = i
                }
              }
            }
            console.log(this.spanArr)
            console.log(this.spanCodeArr)
      },
      objectSpanMethod({ row, column, rowIndex, columnIndex }){
        if(columnIndex==1){
           const _row = this.spanArr[rowIndex]
           const _col = _row > 0 ? 1 : 0
           return {
              rowspan: _row,
              colspan: _col
          }
        }
        if(columnIndex==2){
            const _row = this.spanCodeArr[rowIndex]
            const _col = _row > 0 ? 1 : 0
            return {
               rowspan: _row,
               colspan: _col
            }
        }
      }

  


免責聲明!

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



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