vxe-table 自定义列排序:添加上移/下移/置顶/置尾按钮

0 阅读1分钟

vxe-table 自定义列个性化列支持按钮点击上移/下移/置顶/置尾排序操作 在公司系统管理列表页面中,用户经常需要调整列的显示顺序,以便将常用列放在前面。vxe-table 提供了强大的自定义列功能,除了默认的拖拽排序外,还可以通过配置启用上移/下移和置顶/置尾按钮,让用户通过点击快速调整列顺序。

移和下移排序按钮

通过设置 custom-config.showSortMoveButton 启用上移和下移排序按钮

Video_2026-05-06_182443-ezgif.com-video-to-gif-converter

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

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

const gridOptions = reactive({
  border: true,
  columnConfig: {
    resizable: true
  },
  customConfig: {
    mode: 'modal',
    showSortMoveButton: true
  },
  toolbarConfig: {
    custom: true
  },
  columns: [
    { type: 'seq', width: 70 },
    { field: 'name', title: 'Name' },
    { field: 'sex', title: 'Sex' },
    { field: 'age', title: 'Age' }
  ],
  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>

置顶和置尾排序按钮

设置 custom-config.showSortPutButton 启用置顶和置尾排序按钮

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

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

const gridOptions = reactive({
  border: true,
  columnConfig: {
    resizable: true
  },
  customConfig: {
    mode: 'modal',
    showSortPutButton: true
  },
  toolbarConfig: {
    custom: true
  },
  columns: [
    { type: 'seq', width: 70 },
    { field: 'name', title: 'Name' },
    { field: 'sex', title: 'Sex' },
    { field: 'age', title: 'Age' }
  ],
  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>

vxetable.cn