柏青 發表於 2025-5-20 11:45:00

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

<p>使用 vxe-table 合并单元格、分组列头的详细用法</p>
<p>查看官网:https://vxetable.cn<br>
gitbub:https://github.com/x-extends/vxe-table<br>
gitee:https://gitee.com/x-extends/vxe-table</p>
<h2 id="代码">代码</h2>
<p>通过设置 merge-cells={ row: 第几行开始, col: 第几列开始, rowspan: 合并多少行, colspan: 合并多少列 } 配置合并规则</p>
<p><img src="https://img2024.cnblogs.com/blog/3563285/202505/3563285-20250520114522086-1460839841.png"></p>
<pre><code class="language-html">&lt;template&gt;
&lt;div&gt;
    &lt;vxe-grid v-bind="gridOptions"&gt;&lt;/vxe-grid&gt;
&lt;/div&gt;
&lt;/template&gt;

&lt;script setup&gt;
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: '' }
]
})
&lt;/script&gt;
</code></pre>
<p>https://gitee.com/x-extends/vxe-table</p><br><br>
来源:https://www.cnblogs.com/qaz666/p/18886491
頁: [1]
查看完整版本: 使用 vxe-table 合并单元格、分组列头的详细用法