mirror of
https://github.com/ant-design/ant-design.git
synced 2025-08-06 07:56:28 +08:00
fix(Table): onChange sorter
param types (#36710)
* fix(types): fixes `sorter` param types * chore: add test case * Update type.test.tsx * Update type.test.tsx
This commit is contained in:
parent
772c251ec5
commit
9e7e32b60c
@ -61,7 +61,7 @@ interface ChangeEventInfo<RecordType> {
|
||||
total?: number;
|
||||
};
|
||||
filters: Record<string, FilterValue | null>;
|
||||
sorter: SorterResult<RecordType> | SorterResult<RecordType>[];
|
||||
sorter: SorterResult<RecordType> | SorterResult<RecordType[]>;
|
||||
|
||||
filterStates: FilterState<RecordType>[];
|
||||
sorterStates: SortState<RecordType>[];
|
||||
@ -92,7 +92,7 @@ export interface TableProps<RecordType>
|
||||
onChange?: (
|
||||
pagination: TablePaginationConfig,
|
||||
filters: Record<string, FilterValue | null>,
|
||||
sorter: SorterResult<RecordType> | SorterResult<RecordType>[],
|
||||
sorter: SorterResult<RecordType> | SorterResult<RecordType[]>,
|
||||
extra: TableCurrentDataSource<RecordType>,
|
||||
) => void;
|
||||
rowSelection?: TableRowSelection<RecordType>;
|
||||
@ -263,7 +263,7 @@ function InternalTable<RecordType extends object = any>(
|
||||
|
||||
// ============================ Sorter =============================
|
||||
const onSorterChange = (
|
||||
sorter: SorterResult<RecordType> | SorterResult<RecordType>[],
|
||||
sorter: SorterResult<RecordType> | SorterResult<RecordType[]>,
|
||||
sorterStates: SortState<RecordType>[],
|
||||
) => {
|
||||
triggerOnChange(
|
||||
|
@ -36,6 +36,12 @@ describe('Table.typescript', () => {
|
||||
const table = <Table<RecordType> dataSource={[{ key: 'Bamboo' }]} />;
|
||||
expect(table).toBeTruthy();
|
||||
});
|
||||
|
||||
it('Sorter types', () => {
|
||||
const table = <Table onChange={(_pagination, _filters, sorter) => sorter.field} />;
|
||||
|
||||
expect(table).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Table.typescript types', () => {
|
||||
|
@ -247,7 +247,7 @@ function stateToInfo<RecordType>(sorterStates: SortState<RecordType>) {
|
||||
|
||||
function generateSorterInfo<RecordType>(
|
||||
sorterStates: SortState<RecordType>[],
|
||||
): SorterResult<RecordType> | SorterResult<RecordType>[] {
|
||||
): SorterResult<RecordType> | SorterResult<RecordType[]> {
|
||||
const list = sorterStates.filter(({ sortOrder }) => sortOrder).map(stateToInfo);
|
||||
|
||||
// =========== Legacy compatible support ===========
|
||||
@ -259,11 +259,7 @@ function generateSorterInfo<RecordType>(
|
||||
};
|
||||
}
|
||||
|
||||
if (list.length <= 1) {
|
||||
return list[0] || {};
|
||||
}
|
||||
|
||||
return list;
|
||||
return list[0] || {};
|
||||
}
|
||||
|
||||
export function getSortData<RecordType>(
|
||||
@ -324,7 +320,7 @@ interface SorterConfig<RecordType> {
|
||||
prefixCls: string;
|
||||
mergedColumns: ColumnsType<RecordType>;
|
||||
onSorterChange: (
|
||||
sorterResult: SorterResult<RecordType> | SorterResult<RecordType>[],
|
||||
sorterResult: SorterResult<RecordType> | SorterResult<RecordType[]>,
|
||||
sortStates: SortState<RecordType>[],
|
||||
) => void;
|
||||
sortDirections: SortOrder[];
|
||||
@ -343,7 +339,7 @@ export default function useFilterSorter<RecordType>({
|
||||
TransformColumns<RecordType>,
|
||||
SortState<RecordType>[],
|
||||
ColumnTitleProps<RecordType>,
|
||||
() => SorterResult<RecordType> | SorterResult<RecordType>[],
|
||||
() => SorterResult<RecordType> | SorterResult<RecordType[]>,
|
||||
] {
|
||||
const [sortStates, setSortStates] = React.useState<SortState<RecordType>[]>(
|
||||
collectSortStates(mergedColumns, true),
|
||||
|
Loading…
Reference in New Issue
Block a user