vxe-table v4.8+ 实现拖拽行调整顺序、行拖动顺序调整排序、列拖拽调整顺序、列排序拖拽
Vxe UI vue vxe-table v4.8+ 实现拖拽行调整顺序、行拖动顺序调整排序、列拖拽调整顺序、列排序拖拽
安装
npm install vxe-pc-ui@4.2.42 vxe-table@4.8.1
main.js
// ...
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')
// ...
列拖拽
通过工具栏启用 custom 自定义列功能,默认就只差拖拽排序、冻结列等功能。
<template>
<div>
<vxe-grid v-bind="gridOptions"></vxe-grid>
</div>
</template>
<script setup>
import { reactive } from 'vue'
const gridOptions = reactive({
border: true,
toolbarConfig: {
custom: true
},
columns: [
{ type: 'seq', width: 70 },
{ field: 'name', title: 'Name' },
{ field: 'role', title: 'role' },
{ field: 'sex', title: 'Sex' },
{ field: 'age', title: 'Age' },
{ field: 'address', title: 'address' }
],
data: [
{ id: 10001, name: 'Test1', role: 'Develop', sex: 'Man', age: 28, address: 'test abc' },
{ id: 10002, name: 'Test2', role: 'Test', sex: 'Women', age: 22, address: 'Guangzhou' },
{ id: 10003, name: 'Test3', role: 'PM', sex: 'Man', age: 32, address: 'Shanghai' },
{ id: 10004, name: 'Test4', role: 'Designer', sex: 'Women', age: 24, address: 'Shanghai' }
]
})
</script>
行拖拽
参数 row-config.drag 开启行拖拽功能,需要注意操作 Dom 功能要设置 rowConfig.useKey 和 columnConfig.useKey ,然后再指定拖放按钮放哪一列 drag-sort=“true”,这样就可以开启行拖拽功能了,使用非简单。
<template>
<div>
<vxe-grid v-bind="gridOptions"></vxe-grid>
</div>
</template>
<script setup>
import { reactive } from 'vue'
const gridOptions = reactive({
border: true,
rowConfig: {
useKey: true,
drag: true
},
columnConfig: {
useKey: true
},
columns: [
{ field: 'name', title: 'Name' },
{ field: 'role', title: 'Role', dragSort: true },
{ field: 'sex', title: 'Sex' },
{ field: 'age', title: 'Age' },
{ field: 'address', title: 'Address' }
],
data: [
{ id: 10001, name: 'Test1', role: 'Develop', sex: 'Man', age: 28, address: 'test abc' },
{ id: 10002, name: 'Test2', role: 'Test', sex: 'Women', age: 22, address: 'Guangzhou' },
{ id: 10003, name: 'Test3', role: 'PM', sex: 'Man', age: 32, address: 'Shanghai' },
{ id: 10004, name: 'Test4', role: 'Designer', sex: 'Women', age: 24, address: 'Shanghai' }
]
})
</script>
github https://github.com/x-extends/vxe-table
gitee
原文地址:https://blog.csdn.net/xlz26296/article/details/143569511
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!