Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: VbenVxeGrid default sort not working #5125

Closed
5 tasks done
han2-n opened this issue Dec 13, 2024 · 3 comments · Fixed by #5141
Closed
5 tasks done

Bug: VbenVxeGrid default sort not working #5125

han2-n opened this issue Dec 13, 2024 · 3 comments · Fixed by #5141
Labels
bug Something isn't working

Comments

@han2-n
Copy link

han2-n commented Dec 13, 2024

Version

Vben Admin V5

Describe the bug?

When i config default sort like vxe-table sort
At the first time, sorts param is empty

Reproduction

// Grid configuration

const gridOptions: VxeGridProps<RowType> = {
  checkboxConfig: {
    highlight: true,
    labelField: 'name',
  },
  columns: [
    { title: '序号', type: 'seq', width: 50 },
    { align: 'left', title: 'Name', type: 'checkbox', width: 100 },
    { field: 'category', sortable: true, title: 'Category' }, // change here
    { field: 'color', title: 'Color' },
    { field: 'productName', title: 'Product Name' },
    { field: 'price', title: 'Price' },
    { field: 'releaseDate', formatter: 'formatDateTime', title: 'DateTime' },
  ],
  exportConfig: {},
  height: 'auto',
  keepSource: true,
  proxyConfig: {
    ajax: {
      query: async ({ page, sort, sorts }) => {
        console.log('🚀 come here baby ======> ~ query: ~ sort:', sort);
        console.log('🚀 come here baby ======> ~ query: ~ sorts:', sorts);
        return await getExampleTableApi({
          page: page.currentPage,
          pageSize: page.pageSize,
        });
      },
    },
    sort: true, // change here
  },
  sortConfig: { // change here
    defaultSort: {
      field: 'category',
      order: 'desc',
    },
    remote: true,
  },
  toolbarConfig: {
    custom: true,
    export: true,
    // import: true,
    refresh: true,
    zoom: true,
  },
};

The first time call method ajax
image

Expect result:
The default sort must have a value the first time.

System Info

System:
    OS: Windows 10 10.0.19045
    CPU: (12) x64 Intel(R) Core(TM) i5-10400 CPU @ 2.90GHz
    Memory: 602.43 MB / 15.85 GB
  Binaries:
    Node: 20.12.2 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.19 - ~\scoop\apps\yarn\current\bin\yarn.CMD
    npm: 10.5.0 - C:\Program Files\nodejs\npm.CMD
    pnpm: 9.13.2 - ~\AppData\Local\pnpm\pnpm.EXE
    bun: 1.1.18 - ~\AppData\Roaming\npm\bun.CMD
  Browsers:
    Internet Explorer: 11.0.19041.4355

Relevant log output

No response

Validations

@mynetfan
Copy link
Collaborator

This is a VxeTable bug.
If autoLoad is set to false, the sorting parameters will be missing when the table is refreshed for the first time

@mynetfan mynetfan added bug Something isn't working upstream and removed bug: pending triage labels Dec 14, 2024
@kexin8
Copy link

kexin8 commented Dec 14, 2024

版本:5.5.1,将autoLoad设置为true,也不生效

@mynetfan
Copy link
Collaborator

mynetfan commented Dec 14, 2024

版本:5.5.1,将autoLoad设置为true,也不生效

那是因为useVxeGrid重新包装时,传入VxeGrid的autoLoad永远是false,由useVxeGrid内部管理了自动刷新的逻辑。另外,VxeTable的刷新按钮默认code是reload,如果需要保持排序数据,配置toolbarConfig时refresh不要传true,传{code: 'query'},这样的话从第二次刷新开始,排序数据就会有效

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants