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

相关推荐
Setsuna_F_Seiei20 小时前
性能优化 - 列表分页查询的优化
前端·vue.js·性能优化
Setsuna_F_Seiei20 小时前
性能优化 - Vue.js 的懒加载的优化封装
前端·vue.js·性能优化
小码哥0681 天前
租房平台源码部署验收:房源样例、区域字典与看房预约逐项验证
前端·javascript·vue.js·租房小程序·租房系统·租房软件
1-1=01 天前
Vue 全局事件总线
前端·javascript·vue.js
徐小夕1 天前
JitKnow AI知识库:把任何文档,一键变成可访问和可配置的Wiki站点
前端·vue.js·github
夏与冰1 天前
Vue2项目动态路由的实现思路
vue.js
北城笑笑2 天前
Vue 112 ,下篇:前端 dist 还原成 Vue3 + Vite 项目( krpano 全景接入与页面适配实战,Vue2 → Vue3 )
前端·javascript·vue.js·3d·前端框架·vue·webgl
徐小夕2 天前
实测 10 个前端 UI 生成开源 Skill|AI 输出直达上线标准
前端·vue.js·github
软件技术NINI2 天前
基于SpringBootVue 的出租车拼车系统
vue.js·spring boot·spring·毕业设计·毕设
code2cat2 天前
Vue项目实战之任务保存:编辑失败后,怎样保留输入再重试
前端·javascript·vue.js