vxe-grid 通过配置式给单元格字段格式化树结构数据,转换树结构节点

vxe-grid 通过配置式给单元格字段格式化树结构数据,转换树结构节点
比如用户自定义配置好的数据源,通过在列中配置好数据,全 json 方式直接返回给前端渲染,不需要写任何格式化方法。

官网:https://vxetable.cn

npm install vxe-pc-ui@4.3.90 vxe-table@4.11.0
// ...
import VxeUI from 'vxe-pc-ui'
import 'vxe-pc-ui/lib/style.css'
import VxeUITable from 'vxe-table'
import 'vxe-table/lib/style.css'
// ...

createApp(App).use(VxeUI).use(VxeUITable).mount('#app')
// ...

效果

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

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

const gridOptions = reactive({
  border: true,
  showOverflow: true,
  columns: [
    { type: 'seq', width: 70 },
    { field: 'name', title: 'Name', minWidth: 200 },
    {
	    field: 'city',
	    title: 'City',
	    width: 300,
	    cellRender: {
		  name: 'formatTree',
		  options: [
		    {
		      label: '广东省',
		      value: '1',
		      children: [
		        { label: '深圳市', value: '1-1' },
		        { label: '广州市', value: '1-2' }
		      ]
		    },
		    {
		      label: '北京',
		      value: '2',
		      children: [
		        { label: '东城区', value: '2-1' },
		        { label: '西城区', value: '2-2' }
		      ]
		    }
		  ]
		}
    }
  ],
  data: [
    { id: 10001, name: 'Test1', role: 'Develop', city: null },
    { id: 10002, name: 'Test2', role: 'Test', city: '1-2' },
    { id: 10003, name: 'Test3', role: 'PM', city: '1-1' },
    { id: 10003, name: 'Test4', role: 'Develop', city: ['1-1', '2-1'] }
  ]
})
</script>

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

来源链接:https://www.cnblogs.com/qaz666/p/18720507

© 版权声明
THE END
支持一下吧
点赞14 分享
评论 抢沙发
头像
请文明发言!
提交
头像

昵称

取消
昵称表情代码快捷回复

    暂无评论内容