chore: fix table ajax demo (#49513)

* 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 <afc163@gmail.com>

---------

Signed-off-by: afc163 <afc163@gmail.com>
Co-authored-by: afc163 <afc163@gmail.com>
pull/49522/head
叶枫 7 months ago committed by GitHub
parent b7208603ee
commit 5e4019f90d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -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<T> = TableProps<T>['columns'];
@ -20,8 +21,8 @@ interface DataType {
interface TableParams {
pagination?: TablePaginationConfig;
sortField?: string;
sortOrder?: string;
sortField?: SorterResult<any>['field'];
sortOrder?: SorterResult<any>['order'];
filters?: Parameters<GetProp<TableProps, 'onChange'>>[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

Loading…
Cancel
Save