Vxe UI vue vxe-table v4.9+ 实现在表格列中直接拖拽排序,列拖拽排序
安装
npm install vxe-pc-ui@4.3.3 vxe-table@4.9.0
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')
// ...
列拖拽
参数 column-config.drag 开启列拖拽功能,这样就可以开启行拖拽调整顺序功能了。
<template><div><vxe-button status="success" @click="resultEvent">获取数据</vxe-button><vxe-grid ref="gridRef" v-bind="gridOptions"></vxe-grid></div>
</template><script setup>
import { ref, reactive } from 'vue'const gridRef = ref()const gridOptions = reactive({border: true,columnConfig: {useKey: true,drag: true},columns: [{ 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' }]
})const resultEvent = () => {const $grid = gridRef.valueif ($grid) {const { visibleColumn } = $grid.getTableColumn()console.log(visibleColumn)}
}
</script>
同时使用行与列拖拽排序
参数 column-config.drag 和 row-config.drag 开启同时行与列拖拽调整顺序功能,这样就可以开启行拖拽功能了。
<template><div><vxe-button status="success" @click="resultEvent">获取数据</vxe-button><vxe-grid ref="gridRef" v-bind="gridOptions"></vxe-grid></div>
</template><script setup>
import { ref, reactive } from 'vue'interface RowVO {id: numbername: stringrole: stringsex: stringage: numberaddress: string
}const gridRef = ref()const gridOptions = reactive({border: true,columnConfig: {useKey: true,drag: true},rowConfig: {useKey: true,drag: 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' }]
})const resultEvent = () => {const $grid = gridRef.valueif ($grid) {const { visibleColumn } = $grid.getTableColumn()const { visibleData } = $grid.getTableData()console.log(visibleColumn, visibleData)}
}
</script>
github https://github.com/x-extends/vxe-table
gitee