el-table表格合并单元格


 

 

 

 

 
el-table表格通过 :span-method="objectSpanMethod" 可以设置合并单元格

 表格数据

      tableData: [
        {
          id: 1,
          name: 111,
          isInputS: true
        },
        {
          id: 1,
          name: 111,
          isInputS: true
        },
        {
          id: 1,
          name: 111,
          isInputS: true
        },
        {
          id: 2,
          name: 222,
          isInputS: true
        },
        {
          id: 3,
          name: 222,
          isInputS: true
        },
        {
          id: 3,
          name: 222,
          isInputS: true
        }
      ],
    spanArr: [],
 

  

 

 

mounted() {
    let contactDot = 0;
    this.tableData.forEach( (item,index) => {
      if(index===0){
        this.spanArr.push(1)
      }else{
        if(item.id === this.tableData[index-1].id){
          this.spanArr[contactDot] += 1;
          this.spanArr.push(0)
        }else{
          contactDot = index
          this.spanArr.push(1)
        }
      }
    })
  },

  

methods: {
    objectSpanMethod ({ row, column, rowIndex, columnIndex }) {
      // return
      if(columnIndex === 0){
        const _row = this.spanArr[rowIndex]
        const _col = _row>0?1:0;
        return{
          rowspan:_row,
          colspan:_col
        }
      }
       if(columnIndex === 1){
        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