vxe-table 如何使用树层级结构并开启虚拟滚动

vxe-table 如何使用树层级结构并开启虚拟滚动,默认情况下 vxe-table 是支持平级树结构开启虚拟滚动的,会自动转成树结构,但是有时候后端返回的数据是树层级,不是平级。这时候就可以用数据拍平方法实现。

查看官网:https://vxetable.cn

gitbub:https://github.com/x-extends/vxe-table

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

html 复制代码
<template>
  <div>
    <vxe-grid v-bind="gridOptions"></vxe-grid>
  </div>
</template>

<script setup>
import { reactive } from 'vue'
import XEUtils from 'xe-utils'

const gridOptions = reactive({
  border: true,
  treeConfig: {
    rowField: 'id',
    childrenField: 'children'
  },
  columns: [
    { type: 'seq', width: 70 },
    { field: 'name', title: 'Name', minWidth: 300, treeNode: true },
    { field: 'size', title: 'Size' },
    { field: 'type', title: 'Type' },
    { field: 'date', title: 'Date' }
  ],
  data: []
})

const dataList = [
  {id: 10000, name: 'Test1', type: 'mp3', size: 1024, date: '2020-08-01' },
  {
    id: 10050,
    name: 'Test2',
    type: 'mp4',
    size: 0,
    date: '2021-04-01',
    children: [
      {
        id: 24300,
        name: 'Test3',
        type: 'avi',
        size: 1024,
        date: '2020-03-01',
        children: [
          { id: 20045, name: 'Test4', type: 'html', size: 600, date: '2021-04-01' },
          {
            id: 10053,
            name: 'Test5',
            type: 'avi',
            size: 0,
            date: '2021-04-01',
            children: [
              { id: 24330, name: 'Test6', type: 'txt', size: 25, date: '2021-10-01' },
              { id: 21011, name: 'Test7', type: 'pdf', size: 512, date: '2020-01-01' },
              { id: 22200, name: 'Test8', type: 'js', size: 1024, date: '2021-06-01' }
            ]
          }
        ]
      }
    ]
  },
  {
    id: 23666,
    name: 'Test9',
    type: 'xlsx',
    size: 2048,
    date: '2020-11-01',
    children: [
      {
        id: 23677,
        name: 'Test10',
        type: 'js',
        size: 1024,
        date: '2021-06-01',
        children: [
          { id: 23671, name: 'Test11', type: 'js', size: 1024, date: '2021-06-01' },
          { id: 23672, name: 'Test12', type: 'js', size: 1024, date: '2021-06-01' }
        ]
      },
      {
        id: 23688,
        name: 'Test13',
        type: 'js',
        size: 1024,
        date: '2021-06-01',
        children: [
          { id: 23681, name: 'Test14', type: 'js', size: 1024, date: '2021-06-01' },
          { id: 23682, name: 'Test15', type: 'js', size: 1024, date: '2021-06-01' }
        ]
      }
    ]
  },
  {
    id: 24555,
    name: 'Test16',
    type: 'avi',
    size: 224,
    date: '2020-10-01',
    children: [
      { id: 24566, name: 'Test17', type: 'js', size: 1024, date: '2021-06-01' },
      { id: 24577, name: 'Test18', type: 'js', size: 1024, date: '2021-06-01' }
    ]
  }
]
// 使用函数库工具类处理数据
gridOptions.data = XEUtils.toTreeArray(dataList, { children: 'children', key: 'id', parentKey: 'parentId' })
</script>

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

相关推荐
ruanno_top4 小时前
能点,但 Tab 不到:两个组件把「可操作」做了一半
vue.js
爱吃烧烤的技术渣4 小时前
别再手写 CRUD 了:我把 Element Plus 的工作量压缩成一份列 schema
前端·vue.js
徐小夕7 小时前
万字长文!DeepSeek Super-agent × 企业知识库架构深度拆解与落地实践
前端·vue.js·github
ruanno_top1 天前
倒计时该用 deadline 还是每秒减一?我把两种写法都跑了一遍
vue.js
徐小夕1 天前
下载量超 30 万的开源智能体 Prime Agent:它把自己从 TypeScript 重写成了 Rust
前端·vue.js·github
toooooop81 天前
CRMEB 故障排查笔记:安全网关只放行 GET/POST 怎么办
前端·javascript·vue.js·thinkphp6·crmeb
软件技术NINI1 天前
基于SpringBoot和Vue的项目评审系统
javascript·vue.js·spring boot·后端·spring·毕业设计·毕设
FRing032 天前
vue2干货总结3(computed计算属性、watch监听器)
开发语言·前端·vue.js·vue2
Java小卷2 天前
JuanForm vs FormCreate!Vue3 表单引擎联动配置 PK!
vue.js·低代码
小郎君6582 天前
Vue 多标签页的加载态设计:为什么我没有用 Suspense 实现 PageLoading
vue.js·算法