el-table分组合并行

接到一个需求,把数据按照天 分组显示 时间单独一行,数据在一块

这里新知识点:span-method

复制代码
const plist = ref([{
dateHeader:'2024-01-23',
list:[{dateHeader:'2024-01-23'},{name:'数据1',id:1},{name:'数据2',id:2}]
},
{
dateHeader:'2024-01-24',
list:[{dateHeader:'2024-01-24'},{name:'数据22',id:1},{name:'数据23',id:2}]
},
{
dateHeader:'2024-01-25',
list:[{dateHeader:'2024-01-25'},{name:'数据33',id:1},{name:'数据34',id:2}]
}])
const tableConfig = reactive([
  { prop: 'name', label: '计划名称', minWidth: '10' },
  { prop: 'id', label: 'ID', minWidth: '15' },
  { prop: 'operation', label: '操作', minWidth: '15' }
]);
     
const arraySpanMethod = (row, column, rowIndex, columnIndex) => {
  let hideColArr = [1, 2];//数组是根据要合并哪几个来定
  if (row.rowIndex == 0) {
    if (hideColArr.includes(row.columnIndex)) {
      return { display: 'none' };
    }
    return { rowspan: 1, colspan: 3 };
  }
};

 <template v-for="(item2, index2) in plist" :key="index2"> 
 <el-table
          :data="item2.list"
          :show-header="index2 === 0"
          :span-method="arraySpanMethod"
          :cell-style="{ padding: '3px' }"
        >
          <el-table-column
            v-for="(value, key) in tableConfig"
            :key="key"
            :prop="value.prop"
            :label="value.label"
            :min-width="value.minWidth"
          >
            <template #default="scope">
              <div v-if="scope.row.dateHeader">{{ scope.row.dateHeader }}</div>
            </template>
          </el-table-column>
        </el-table>
            </template>
相关推荐
running up38 分钟前
Java集合框架之ArrayList与LinkedList详解
javascript·ubuntu·typescript
xiaoxue..43 分钟前
React 之 Hooks
前端·javascript·react.js·面试·前端框架
Alair‎1 小时前
300TypeScript基础知识
javascript
莫物1 小时前
element el-table表格 添加唯一标识
前端·javascript·vue.js
Shirley~~1 小时前
PPTist 幻灯片工具栏Toolbar部分
开发语言·前端·javascript
|晴 天|1 小时前
Promise 与 async/await 错误处理最佳实践指南
开发语言·前端·javascript
苹果电脑的鑫鑫1 小时前
.eslintrc.js这个文件作用
开发语言·javascript·ecmascript
vx_bisheyuange1 小时前
基于SpringBoot的便利店信息管理系统
前端·javascript·vue.js·毕业设计
晚烛1 小时前
智启工厂脉搏:基于 OpenHarmony + Flutter 的信创工业边缘智能平台构建实践
前端·javascript·flutter
Zsnoin能1 小时前
都快2026了,还有人不会国际化和暗黑主题适配吗,一篇文章彻底解决
前端·javascript