remote.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <script lang="ts" setup>
  2. import type { VxeGridProps } from '#/adapter/vxe-table';
  3. import { Page } from '@vben/common-ui';
  4. import { Button } from 'ant-design-vue';
  5. import { useVbenVxeGrid } from '#/adapter/vxe-table';
  6. import { getExampleTableApi } from '#/api';
  7. interface RowType {
  8. category: string;
  9. color: string;
  10. id: string;
  11. price: string;
  12. productName: string;
  13. releaseDate: string;
  14. }
  15. const gridOptions: VxeGridProps<RowType> = {
  16. checkboxConfig: {
  17. highlight: true,
  18. labelField: 'name',
  19. },
  20. columns: [
  21. { title: '序号', type: 'seq', width: 50 },
  22. { align: 'left', title: 'Name', type: 'checkbox', width: 100 },
  23. { field: 'category', sortable: true, title: 'Category' },
  24. { field: 'color', sortable: true, title: 'Color' },
  25. { field: 'productName', sortable: true, title: 'Product Name' },
  26. { field: 'price', sortable: true, title: 'Price' },
  27. { field: 'releaseDate', formatter: 'formatDateTime', title: 'DateTime' },
  28. ],
  29. exportConfig: {},
  30. height: 'auto',
  31. keepSource: true,
  32. proxyConfig: {
  33. ajax: {
  34. query: async ({ page, sort }) => {
  35. return await getExampleTableApi({
  36. page: page.currentPage,
  37. pageSize: page.pageSize,
  38. sortBy: sort.field,
  39. sortOrder: sort.order,
  40. });
  41. },
  42. },
  43. sort: true,
  44. },
  45. sortConfig: {
  46. defaultSort: { field: 'category', order: 'desc' },
  47. remote: true,
  48. },
  49. toolbarConfig: {
  50. custom: true,
  51. export: true,
  52. // import: true,
  53. refresh: { code: 'query' },
  54. zoom: true,
  55. },
  56. };
  57. const [Grid, gridApi] = useVbenVxeGrid({
  58. gridOptions,
  59. });
  60. </script>
  61. <template>
  62. <Page auto-content-height>
  63. <Grid table-title="数据列表" table-title-help="提示">
  64. <template #toolbar-tools>
  65. <Button class="mr-2" type="primary" @click="() => gridApi.query()">
  66. 刷新当前页面
  67. </Button>
  68. <Button type="primary" @click="() => gridApi.reload()">
  69. 刷新并返回第一页
  70. </Button>
  71. </template>
  72. </Grid>
  73. </Page>
  74. </template>