web建站教程
  1. 首页
  2. vuejs
  3. js
  4. 好玩
  5. seo教程
  6. 前端知识
  7. 百度echarts
  8. 更多
    php入门
    nodejs
    mockjs
    reactjs
    mysql
    wordpress
    织梦cms
    帝国cms
    git教程
    IT知识
    模板大全
    休息站

el-table合并单元格代码介绍

493 ℃
     

vuejs结合el-table开发列表,如何动态合并列单元格。下面web建站小编给大家简单介绍一下实现代码!

1、先在el-table代码中新增如下代码:

:span-method="spanMethod"

2、合并单元格代码(直接复制不需要改动)

mergeCol(id, rowIndex) {
 //this.listData表格数据
 var idName = this.listData[rowIndex][id]
 if (rowIndex > 0) {
   if (this.listData[rowIndex][id] != this.listData[rowIndex - 1][id]) {
       var i = rowIndex
       var num = 0
       while (i < this.listData.length) {
         if (this.listData[i][id] === idName) {
           i++
           num++
         } else {
           i = this.listData.length
         }
       }
       return {
         rowspan: num,
         colspan: 1
       }
    } else {
       return {
           rowspan: 0,
           colspan: 1
       }
    }
  } else {
     let i = rowIndex
     let num = 0
     while (i < this.listData.length) {
       if (this.listData[i][id] === idName) {
           i++
           num++
       } else {
           i = this.listData.length
       }
     }
     return {
       rowspan: num,
       colspan: 1
     }
  }
},

3、根据需要修改合并参数

 spanMethod({ row, column, rowIndex, columnIndex }) {
  switch (columnIndex) {
    case 0:
      return this.mergeCol('name', rowIndex)
    case 1:
      return this.mergeCol('school', rowIndex)
  }
}

el-table表格显示selection多选时对某些复选框设置禁止选中

el-table表格实现多选功能(全选/指定选中/取消选中)

el-table实现拖拽行排序sortablejs

el-dialog中获取el-table组件的ref值报undefined错误!

el-table列表给指定列的文字添加样式,但是列是动态的

标签: el-table, 单元格合并

上面是“el-table合并单元格代码介绍”的全面内容,想了解更多关于 vuejs 内容,请继续关注web建站教程。

当前网址:https://ipkd.cn/webs_3072.html

声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

当前位置: 网站首页 > vuejs
本文共计790个字,预计阅读时长6分钟
生活小工具,收录了80多款小工具
上一篇: 推荐一款可免费商用圆体字库——江城圆体
下一篇: 推荐一款由字制区设计团队的免费综艺字体——字制区喜脉体
x 打工人ai神器