From 5e4019f90d12427255749e7e906633f61b3703bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B6=E6=9E=AB?= <7971419+crazyair@users.noreply.github.com> Date: Thu, 20 Jun 2024 15:07:32 +0800 Subject: [PATCH] chore: fix table ajax demo (#49513) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chroe: fix table ajax demo * chroe: demo * feat: deps 写法 * feat: add filters * feat: remvoe console * Update components/table/demo/ajax.tsx Signed-off-by: afc163 --------- Signed-off-by: afc163 Co-authored-by: afc163 --- components/table/demo/ajax.tsx | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/components/table/demo/ajax.tsx b/components/table/demo/ajax.tsx index c282d40585..89f14bc215 100644 --- a/components/table/demo/ajax.tsx +++ b/components/table/demo/ajax.tsx @@ -1,6 +1,7 @@ import React, { useEffect, useState } from 'react'; -import { Table } from 'antd'; import type { GetProp, TableProps } from 'antd'; +import { Table } from 'antd'; +import type { SorterResult } from 'antd/es/table/interface'; import qs from 'qs'; type ColumnsType = TableProps['columns']; @@ -20,8 +21,8 @@ interface DataType { interface TableParams { pagination?: TablePaginationConfig; - sortField?: string; - sortOrder?: string; + sortField?: SorterResult['field']; + sortOrder?: SorterResult['order']; filters?: Parameters>[1]; } @@ -85,13 +86,20 @@ const App: React.FC = () => { useEffect(() => { fetchData(); - }, [tableParams.pagination?.current, tableParams.pagination?.pageSize]); + }, [ + tableParams.pagination?.current, + tableParams.pagination?.pageSize, + tableParams?.sortOrder, + tableParams?.sortField, + JSON.stringify(tableParams.filters), + ]); const handleTableChange: TableProps['onChange'] = (pagination, filters, sorter) => { setTableParams({ pagination, filters, - ...sorter, + sortOrder: Array.isArray(sorter) ? undefined : sorter.order, + sortField: Array.isArray(sorter) ? undefined : sorter.field, }); // `dataSource` is useless since `pageSize` changed