Ant-Design-Vue动态表头并填充数据

使用Ant Design Vue框架的Table组件时,我们通过配置Table组件的colums属性来生成表头

<a-table :columns="columns" :data-source="data"></a-table>
const columns = [
  {
    dataIndex: 'name',
    key: 'name',
    slots: { title: 'customTitle' },
    scopedSlots: { customRender: 'name' },
  },
  {
    title: 'Age',
    dataIndex: 'age',
    key: 'age',
  },
  {
    title: 'Address',
    dataIndex: 'address',
    key: 'address',
  },
  {
    title: 'Tags',
    key: 'tags',
    dataIndex: 'tags',
    scopedSlots: { customRender: 'tags' },
  },
  {
    title: 'Action',
    key: 'action',
    scopedSlots: { customRender: 'action' },
  },
];

但是,当我们做智能表单项目的需求是,我们要根据数据库储存的JSON对象动态的生成表头。

当时脑子里的第一个想法是,在拿到后台传过来的JSON数据之后在JS中根据JSON对象创建一个新的colums,然后生成动态的表头。这样做肯定是没有问题的,代码省略。

但是后来采取了循环创建 a-table-column 的方式来实现动态表头。个人感觉这样更符合逻辑一些

<a-table>         
     <!-- 定制表格表头 -->
              <template v-for="(item, itemIndex) in widgetData.originalLine.fieldList">
                <a-table-column
                  v-if="hasGrid(item.id)"
                  :title="item.name"
                  :key="item.id"
                  :width="widthCal(item.id)"
                  :align="alignment(item.id)"
                >
                  <template slot-scope="text, record">
                    <div v-if="!item.tableFixedColumnsDisplay">
                      {{ getTableContent(record,item.id) }}
                    </div>
                  </template>
                </a-table-column>
              </template>
<a-table>         

这样就搞定了!

相关推荐

  1. Ant-Design-Vue动态表头填充数据

    2024-06-06 21:56:05       30 阅读
  2. Ant-Design-Vue动态表头填充数据

    2024-06-06 21:56:05       32 阅读
  3. Ant-Design-Vue动态表头填充数据

    2024-06-06 21:56:05       31 阅读
  4. Ant Design Vue 动态表头填充数据

    2024-06-06 21:56:05       28 阅读
  5. Ant-Design-Vue动态表头填充数据

    2024-06-06 21:56:05       32 阅读
  6. Ant-Design-Vue动态表头填充数据

    2024-06-06 21:56:05       33 阅读
  7. Ant-Design-Vue动态表头填充数据

    2024-06-06 21:56:05       24 阅读
  8. ant-desigin-vue动态表头填充数据

    2024-06-06 21:56:05       22 阅读
  9. 使用 Ant Design Vue 实现动态表头数据填充

    2024-06-06 21:56:05       33 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-06-06 21:56:05       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-06-06 21:56:05       106 阅读
  3. 在Django里面运行非项目文件

    2024-06-06 21:56:05       87 阅读
  4. Python语言-面向对象

    2024-06-06 21:56:05       96 阅读

热门阅读

  1. Unreal Engine游戏引擎小白入门指南

    2024-06-06 21:56:05       31 阅读
  2. SQL常用语句--模糊查询LIKE

    2024-06-06 21:56:05       31 阅读
  3. 一篇想要成为Python编程大佬,看这篇就够了

    2024-06-06 21:56:05       36 阅读
  4. 通过Slf4j中的MDC实现在日志中添加用户IP功能

    2024-06-06 21:56:05       33 阅读
  5. BOOT ISO和DVD ISO的区别

    2024-06-06 21:56:05       30 阅读
  6. nacos增加修改配置实时生效

    2024-06-06 21:56:05       31 阅读
  7. redis集群

    2024-06-06 21:56:05       31 阅读
  8. VOJ 圣诞树 题解 最短路径 dijkstra算法

    2024-06-06 21:56:05       33 阅读
  9. Amazon Web Services 问题咨询笔记

    2024-06-06 21:56:05       29 阅读
  10. USB - Linux Drivers介绍

    2024-06-06 21:56:05       32 阅读
  11. 服务器硬件介绍(1)

    2024-06-06 21:56:05       24 阅读
  12. 【Linux】多进程基础

    2024-06-06 21:56:05       23 阅读