From 611ce0d759ec304034bc65bde4b2f6356aa9169e Mon Sep 17 00:00:00 2001 From: chenos Date: Sun, 28 Mar 2021 21:08:54 +0800 Subject: [PATCH] fix: sorter for datetime and number --- packages/app/src/api-client.ts | 1 + packages/app/src/components/pages/AdminLoader/View/Table.tsx | 3 ++- packages/app/src/components/views/SortableTable/index.tsx | 3 +++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/app/src/api-client.ts b/packages/app/src/api-client.ts index 407508399..5ef1010cd 100644 --- a/packages/app/src/api-client.ts +++ b/packages/app/src/api-client.ts @@ -65,6 +65,7 @@ class ApiClient { options.params['filter'] = JSON.stringify(filter); } if (sorter) { + sort = []; const arr = Array.isArray(sorter) ? sorter : [sorter]; arr.forEach(({ order, field }) => { if (order === 'descend') { diff --git a/packages/app/src/components/pages/AdminLoader/View/Table.tsx b/packages/app/src/components/pages/AdminLoader/View/Table.tsx index 1246c14f7..17dfbf05d 100644 --- a/packages/app/src/components/pages/AdminLoader/View/Table.tsx +++ b/packages/app/src/components/pages/AdminLoader/View/Table.tsx @@ -221,7 +221,7 @@ export function Table(props: any) { params, } = useRequest( (params = {}, ...args) => { - const { current, pageSize, sorter, filter, ...restParams } = params; + const { current, pageSize, sorter, filter, ...restParams } = params as any; console.log('paramsparamsparamsparamsparams', params, args); return api .resource(resourceName) @@ -472,6 +472,7 @@ export function Table(props: any) { columns={fields2columns(fields, { associatedKey, refresh })} pagination={false} onChange={(pagination, filters, sorter, extra) => { + console.log({sorter}); run({ ...params[0], sorter }); }} expandable={expandable} diff --git a/packages/app/src/components/views/SortableTable/index.tsx b/packages/app/src/components/views/SortableTable/index.tsx index 08ce5cb02..31b4d1f99 100644 --- a/packages/app/src/components/views/SortableTable/index.tsx +++ b/packages/app/src/components/views/SortableTable/index.tsx @@ -97,6 +97,9 @@ export function fields2columns(fields = [], ctx: any = {}) { if (!field.dataIndex) { field.dataIndex = field.name.split('.'); } + if (['datetime', 'number'].includes(field.interface)) { + field.sorter = true; + } field.render = (value, record, index) => field.interface === 'sort' ? (