使用 vxe-table 合并单元格、分组列头的详细用法


使用 vxe-table 合并单元格、分组列头的详细用法

查看官网:https://vxetable.cn
gitbub:https://github.com/x-extends/vxe-table
gitee:https://gitee.com/x-extends/vxe-table

代码

通过设置 merge-cells={ row: 第几行开始, col: 第几列开始, rowspan: 合并多少行, colspan: 合并多少列 } 配置合并规则

<template>
  <div>
    <vxe-grid v-bind="gridOptions"></vxe-grid>
  </div>
</template>

<script setup>
import { ref, reactive } from 'vue'

const gridOptions = reactive({
  border: true,
  mergeCells: [
    { row: 0, col: 3, rowspan: 4, colspan: 1 },
    { row: 0, col: 4, rowspan: 4, colspan: 1 },
    { row: 0, col: 5, rowspan: 4, colspan: 1 },
    { row: 0, col: 6, rowspan: 4, colspan: 1 },
    { row: 0, col: 7, rowspan: 4, colspan: 1 },
    { row: 0, col: 8, rowspan: 4, colspan: 1 }
  ],
  columns: [
    { type: 'seq', width: 70 },
    { field: 'name', title: 'Name' },
    {
      title: 'Group1',
      field: 'group1',
      headerAlign: 'center',
      children: [
        { field: 'sex', title: 'Sex' },
        { field: 'age', title: 'Age' }
      ]
    },
    {
      title: 'Group2',
      field: 'group2',
      headerAlign: 'center',
      children: [
        {
          field: 'attr1',
          title: 'Attr1',
          headerAlign: 'center',
          children: [
            { field: 'attr3', title: 'Attr3' },
            { field: 'attr4', title: 'Attr4' }
          ]
        },
        {
          field: 'attr2',
          title: 'Attr2',
          headerAlign: 'center',
          children: [
            { field: 'attr5', title: 'Attr5' },
            { field: 'attr6', title: 'Attr6' }
          ]
        }
      ]
    },
    { field: 'address', title: 'Address' }
  ],
  data: [
    { id: 10001, name: 'Test1', role: 'Develop', sex: 'Man', age: 46, attr3: 22, attr4: 100, attr5: 66, attr6: 86, address: 'Guangzhou' },
    { id: 10002, name: 'Test2', role: 'Test', sex: 'Women', age: 0, attr3: 0, attr4: 0, attr5: 0, attr6: 0, address: '' },
    { id: 10003, name: 'Test3', role: 'PM', sex: 'Man', age: 0, attr3: 22, attr4: 0, attr5: 0, attr6: 0, address: '' },
    { id: 10004, name: 'Test4', role: 'Designer', sex: 'Women', age: 0, attr3: 0, attr4: 0, attr5: 0, attr6: 0, address: '' }
  ]
})
</script>

https://gitee.com/x-extends/vxe-table