2023-09-20 11:01:49 +08:00
|
|
|
import type * as React from 'react';
|
2023-10-11 13:55:20 +08:00
|
|
|
import type { Reference } from 'rc-table';
|
2022-05-07 14:31:54 +08:00
|
|
|
import type {
|
2021-11-26 17:50:41 +08:00
|
|
|
FixedType,
|
2023-05-06 15:24:22 +08:00
|
|
|
GetComponentProps,
|
2023-05-22 12:03:57 +08:00
|
|
|
ColumnType as RcColumnType,
|
2022-06-22 14:57:09 +08:00
|
|
|
RenderedCell as RcRenderedCell,
|
2020-02-29 23:11:02 +08:00
|
|
|
} from 'rc-table/lib/interface';
|
2022-06-22 14:57:09 +08:00
|
|
|
import { ExpandableConfig, GetRowKey } from 'rc-table/lib/interface';
|
2023-09-20 11:01:49 +08:00
|
|
|
|
2023-05-22 12:03:57 +08:00
|
|
|
import type { Breakpoint } from '../_util/responsiveObserver';
|
2023-07-05 16:54:04 +08:00
|
|
|
import type { AnyObject } from '../_util/type';
|
2022-05-07 14:31:54 +08:00
|
|
|
import type { CheckboxProps } from '../checkbox';
|
|
|
|
import type { PaginationProps } from '../pagination';
|
2022-06-22 14:57:09 +08:00
|
|
|
import type { TooltipProps } from '../tooltip';
|
2023-05-22 12:03:57 +08:00
|
|
|
import type { INTERNAL_SELECTION_ITEM } from './hooks/useSelection';
|
2023-09-20 11:01:49 +08:00
|
|
|
import type { InternalTableProps, TableProps } from './InternalTable';
|
2023-01-07 21:21:52 +08:00
|
|
|
|
2023-07-05 16:54:04 +08:00
|
|
|
export type RefTable = <RecordType extends AnyObject = AnyObject>(
|
2023-12-27 11:53:19 +08:00
|
|
|
props: React.PropsWithChildren<TableProps<RecordType>> & React.RefAttributes<Reference>,
|
2023-01-07 21:21:52 +08:00
|
|
|
) => React.ReactElement;
|
|
|
|
|
2023-07-05 16:54:04 +08:00
|
|
|
export type RefInternalTable = <RecordType extends AnyObject = AnyObject>(
|
2023-12-27 11:53:19 +08:00
|
|
|
props: React.PropsWithChildren<InternalTableProps<RecordType>> & React.RefAttributes<Reference>,
|
2023-01-07 21:21:52 +08:00
|
|
|
) => React.ReactElement;
|
2020-04-26 16:25:42 +08:00
|
|
|
|
2023-07-05 16:54:04 +08:00
|
|
|
export { ExpandableConfig, GetRowKey };
|
2019-08-05 18:38:10 +08:00
|
|
|
|
2019-11-15 14:35:25 +08:00
|
|
|
export type Key = React.Key;
|
2017-11-21 13:48:37 +08:00
|
|
|
|
2023-09-20 11:01:49 +08:00
|
|
|
export type SafeKey = Exclude<Key, bigint>;
|
|
|
|
|
2019-11-15 14:35:25 +08:00
|
|
|
export type RowSelectionType = 'checkbox' | 'radio';
|
2019-05-07 11:53:08 +08:00
|
|
|
|
2019-11-15 14:35:25 +08:00
|
|
|
export type SelectionItemSelectFn = (currentRowKeys: Key[]) => void;
|
2017-11-21 13:48:37 +08:00
|
|
|
|
2019-11-15 14:35:25 +08:00
|
|
|
export type ExpandType = null | 'row' | 'nest';
|
2017-11-21 13:48:37 +08:00
|
|
|
|
|
|
|
export interface TableLocale {
|
|
|
|
filterTitle?: string;
|
2018-01-11 23:13:42 +08:00
|
|
|
filterConfirm?: React.ReactNode;
|
|
|
|
filterReset?: React.ReactNode;
|
2020-06-18 11:38:43 +08:00
|
|
|
filterEmptyText?: React.ReactNode;
|
2021-09-01 10:49:52 +08:00
|
|
|
filterCheckall?: React.ReactNode;
|
|
|
|
filterSearchPlaceholder?: string;
|
2018-01-11 23:13:42 +08:00
|
|
|
emptyText?: React.ReactNode | (() => React.ReactNode);
|
|
|
|
selectAll?: React.ReactNode;
|
2020-12-29 10:38:43 +08:00
|
|
|
selectNone?: React.ReactNode;
|
2018-01-11 23:13:42 +08:00
|
|
|
selectInvert?: React.ReactNode;
|
2019-11-15 14:35:25 +08:00
|
|
|
selectionAll?: React.ReactNode;
|
2018-09-17 17:57:01 +08:00
|
|
|
sortTitle?: string;
|
2019-07-22 19:28:23 +08:00
|
|
|
expand?: string;
|
|
|
|
collapse?: string;
|
2020-02-29 22:01:13 +08:00
|
|
|
triggerDesc?: string;
|
|
|
|
triggerAsc?: string;
|
|
|
|
cancelSort?: string;
|
2017-11-21 13:48:37 +08:00
|
|
|
}
|
|
|
|
|
2019-11-15 14:35:25 +08:00
|
|
|
export type SortOrder = 'descend' | 'ascend' | null;
|
2018-05-07 12:32:26 +08:00
|
|
|
|
2022-12-13 14:57:40 +08:00
|
|
|
const TableActions = ['paginate', 'sort', 'filter'] as const;
|
2023-12-27 14:42:51 +08:00
|
|
|
export type TableAction = (typeof TableActions)[number];
|
2020-06-28 22:41:59 +08:00
|
|
|
|
2019-11-15 14:35:25 +08:00
|
|
|
export type CompareFn<T> = (a: T, b: T, sortOrder?: SortOrder) => number;
|
2019-01-17 13:44:15 +08:00
|
|
|
|
2019-11-15 14:35:25 +08:00
|
|
|
export interface ColumnFilterItem {
|
|
|
|
text: React.ReactNode;
|
2023-09-20 11:01:49 +08:00
|
|
|
value: React.Key | boolean;
|
2019-11-15 14:35:25 +08:00
|
|
|
children?: ColumnFilterItem[];
|
2019-01-17 13:44:15 +08:00
|
|
|
}
|
|
|
|
|
2019-11-15 14:35:25 +08:00
|
|
|
export interface ColumnTitleProps<RecordType> {
|
|
|
|
/** @deprecated Please use `sorterColumns` instead. */
|
|
|
|
sortOrder?: SortOrder;
|
|
|
|
/** @deprecated Please use `sorterColumns` instead. */
|
|
|
|
sortColumn?: ColumnType<RecordType>;
|
|
|
|
sortColumns?: { column: ColumnType<RecordType>; order: SortOrder }[];
|
2019-06-16 20:51:47 +08:00
|
|
|
|
2022-09-19 15:29:26 +08:00
|
|
|
filters?: Record<string, FilterValue>;
|
2019-08-28 02:35:39 +08:00
|
|
|
}
|
|
|
|
|
2019-11-15 14:35:25 +08:00
|
|
|
export type ColumnTitle<RecordType> =
|
|
|
|
| React.ReactNode
|
|
|
|
| ((props: ColumnTitleProps<RecordType>) => React.ReactNode);
|
2019-08-28 02:35:39 +08:00
|
|
|
|
2021-02-20 16:32:59 +08:00
|
|
|
export type FilterValue = (Key | boolean)[];
|
2023-09-20 11:01:49 +08:00
|
|
|
export type FilterKey = (string | number)[] | null;
|
2023-07-05 16:54:04 +08:00
|
|
|
export type FilterSearchType<RecordType = AnyObject> =
|
2022-09-22 10:13:07 +08:00
|
|
|
| boolean
|
|
|
|
| ((input: string, record: RecordType) => boolean);
|
2021-01-05 15:54:36 +08:00
|
|
|
export interface FilterConfirmProps {
|
|
|
|
closeDropdown: boolean;
|
|
|
|
}
|
|
|
|
|
2019-11-15 14:35:25 +08:00
|
|
|
export interface FilterDropdownProps {
|
|
|
|
prefixCls: string;
|
2020-04-03 20:15:27 +08:00
|
|
|
setSelectedKeys: (selectedKeys: React.Key[]) => void;
|
2019-11-15 14:35:25 +08:00
|
|
|
selectedKeys: React.Key[];
|
2022-09-29 14:15:11 +08:00
|
|
|
/**
|
|
|
|
* Confirm filter value, if you want to close dropdown before commit, you can call with
|
|
|
|
* {closeDropdown: true}
|
|
|
|
*/
|
2021-02-05 11:19:57 +08:00
|
|
|
confirm: (param?: FilterConfirmProps) => void;
|
2019-11-25 15:16:59 +08:00
|
|
|
clearFilters?: () => void;
|
2019-11-15 14:35:25 +08:00
|
|
|
filters?: ColumnFilterItem[];
|
2022-09-29 14:15:11 +08:00
|
|
|
/** Only close filterDropdown */
|
|
|
|
close: () => void;
|
2019-11-15 14:35:25 +08:00
|
|
|
visible: boolean;
|
|
|
|
}
|
|
|
|
|
2022-04-08 22:55:42 +08:00
|
|
|
export interface ColumnType<RecordType> extends Omit<RcColumnType<RecordType>, 'title'> {
|
2019-11-15 14:35:25 +08:00
|
|
|
title?: ColumnTitle<RecordType>;
|
|
|
|
// Sorter
|
|
|
|
sorter?:
|
|
|
|
| boolean
|
|
|
|
| CompareFn<RecordType>
|
|
|
|
| {
|
2020-09-11 12:25:22 +08:00
|
|
|
compare?: CompareFn<RecordType>;
|
2019-11-15 14:35:25 +08:00
|
|
|
/** Config multiple sorter order priority */
|
2020-09-11 12:25:22 +08:00
|
|
|
multiple?: number;
|
2019-11-15 14:35:25 +08:00
|
|
|
};
|
|
|
|
sortOrder?: SortOrder;
|
|
|
|
defaultSortOrder?: SortOrder;
|
2019-01-08 17:27:41 +08:00
|
|
|
sortDirections?: SortOrder[];
|
2023-05-22 18:03:45 +08:00
|
|
|
sortIcon?: (props: { sortOrder: SortOrder }) => React.ReactNode;
|
2021-02-01 10:15:39 +08:00
|
|
|
showSorterTooltip?: boolean | TooltipProps;
|
2019-10-22 11:54:03 +08:00
|
|
|
|
2019-11-15 14:35:25 +08:00
|
|
|
// Filter
|
2020-03-03 18:18:19 +08:00
|
|
|
filtered?: boolean;
|
2019-11-15 14:35:25 +08:00
|
|
|
filters?: ColumnFilterItem[];
|
|
|
|
filterDropdown?: React.ReactNode | ((props: FilterDropdownProps) => React.ReactNode);
|
|
|
|
filterMultiple?: boolean;
|
2021-02-20 16:32:59 +08:00
|
|
|
filteredValue?: FilterValue | null;
|
|
|
|
defaultFilteredValue?: FilterValue | null;
|
2019-11-15 14:35:25 +08:00
|
|
|
filterIcon?: React.ReactNode | ((filtered: boolean) => React.ReactNode);
|
2021-09-01 10:49:52 +08:00
|
|
|
filterMode?: 'menu' | 'tree';
|
2022-09-22 10:13:07 +08:00
|
|
|
filterSearch?: FilterSearchType<ColumnFilterItem>;
|
2023-09-20 11:01:49 +08:00
|
|
|
onFilter?: (value: React.Key | boolean, record: RecordType) => boolean;
|
2022-08-22 11:19:53 +08:00
|
|
|
filterDropdownOpen?: boolean;
|
2022-08-22 15:37:51 +08:00
|
|
|
onFilterDropdownOpenChange?: (visible: boolean) => void;
|
2022-03-23 19:29:05 +08:00
|
|
|
filterResetToDefaultFilteredValue?: boolean;
|
2020-04-24 12:17:42 +08:00
|
|
|
|
|
|
|
// Responsive
|
|
|
|
responsive?: Breakpoint[];
|
2022-09-06 21:46:49 +08:00
|
|
|
|
|
|
|
// Deprecated
|
|
|
|
/** @deprecated Please use `filterDropdownOpen` instead */
|
|
|
|
filterDropdownVisible?: boolean;
|
|
|
|
/** @deprecated Please use `onFilterDropdownOpenChange` instead */
|
|
|
|
onFilterDropdownVisibleChange?: (visible: boolean) => void;
|
2017-11-21 13:48:37 +08:00
|
|
|
}
|
|
|
|
|
2020-03-20 23:33:14 +08:00
|
|
|
export interface ColumnGroupType<RecordType> extends Omit<ColumnType<RecordType>, 'dataIndex'> {
|
2019-11-25 15:16:59 +08:00
|
|
|
children: ColumnsType<RecordType>;
|
2019-11-19 10:03:03 +08:00
|
|
|
}
|
|
|
|
|
2019-11-17 17:57:35 +08:00
|
|
|
export type ColumnsType<RecordType = unknown> = (
|
|
|
|
| ColumnGroupType<RecordType>
|
2019-12-25 19:09:17 +08:00
|
|
|
| ColumnType<RecordType>
|
|
|
|
)[];
|
2017-11-21 13:48:37 +08:00
|
|
|
|
|
|
|
export interface SelectionItem {
|
|
|
|
key: string;
|
|
|
|
text: React.ReactNode;
|
2019-09-28 16:20:19 +08:00
|
|
|
onSelect?: SelectionItemSelectFn;
|
2017-11-21 13:48:37 +08:00
|
|
|
}
|
|
|
|
|
2019-11-15 14:35:25 +08:00
|
|
|
export type SelectionSelectFn<T> = (
|
|
|
|
record: T,
|
|
|
|
selected: boolean,
|
2020-12-04 19:47:30 +08:00
|
|
|
selectedRows: T[],
|
2019-11-15 14:35:25 +08:00
|
|
|
nativeEvent: Event,
|
|
|
|
) => void;
|
2017-11-21 13:48:37 +08:00
|
|
|
|
2022-05-18 11:59:00 +08:00
|
|
|
export type RowSelectMethod = 'all' | 'none' | 'invert' | 'single' | 'multiple';
|
|
|
|
|
2019-11-15 14:35:25 +08:00
|
|
|
export interface TableRowSelection<T> {
|
2020-06-28 22:41:59 +08:00
|
|
|
/** Keep the selection keys in list even the key not exist in `dataSource` anymore */
|
|
|
|
preserveSelectedRowKeys?: boolean;
|
2017-11-21 13:48:37 +08:00
|
|
|
type?: RowSelectionType;
|
2019-11-15 14:35:25 +08:00
|
|
|
selectedRowKeys?: Key[];
|
2021-03-25 09:11:39 +08:00
|
|
|
defaultSelectedRowKeys?: Key[];
|
2022-05-18 11:59:00 +08:00
|
|
|
onChange?: (selectedRowKeys: Key[], selectedRows: T[], info: { type: RowSelectMethod }) => void;
|
2020-03-19 23:58:25 +08:00
|
|
|
getCheckboxProps?: (record: T) => Partial<Omit<CheckboxProps, 'checked' | 'defaultChecked'>>;
|
2019-11-15 14:35:25 +08:00
|
|
|
onSelect?: SelectionSelectFn<T>;
|
2022-05-14 16:41:34 +08:00
|
|
|
/** @deprecated This function is deprecated and should use `onChange` instead */
|
2019-11-15 14:35:25 +08:00
|
|
|
onSelectMultiple?: (selected: boolean, selectedRows: T[], changeRows: T[]) => void;
|
2022-05-14 16:41:34 +08:00
|
|
|
/** @deprecated This function is deprecated and should use `onChange` instead */
|
2019-11-15 14:35:25 +08:00
|
|
|
onSelectAll?: (selected: boolean, selectedRows: T[], changeRows: T[]) => void;
|
2022-05-14 16:41:34 +08:00
|
|
|
/** @deprecated This function is deprecated and should use `onChange` instead */
|
2019-11-15 14:35:25 +08:00
|
|
|
onSelectInvert?: (selectedRowKeys: Key[]) => void;
|
2022-05-14 16:41:34 +08:00
|
|
|
/** @deprecated This function is deprecated and should use `onChange` instead */
|
2020-12-29 10:38:43 +08:00
|
|
|
onSelectNone?: () => void;
|
2020-04-22 21:59:18 +08:00
|
|
|
selections?: INTERNAL_SELECTION_ITEM[] | boolean;
|
2020-05-29 23:50:56 +08:00
|
|
|
hideSelectAll?: boolean;
|
2021-11-26 17:50:41 +08:00
|
|
|
fixed?: FixedType;
|
2019-11-15 14:35:25 +08:00
|
|
|
columnWidth?: string | number;
|
2023-10-24 16:05:29 +08:00
|
|
|
columnTitle?: React.ReactNode | ((checkboxNode: React.ReactNode) => React.ReactNode);
|
2020-06-28 22:41:59 +08:00
|
|
|
checkStrictly?: boolean;
|
2020-02-29 23:11:02 +08:00
|
|
|
renderCell?: (
|
|
|
|
value: boolean,
|
|
|
|
record: T,
|
|
|
|
index: number,
|
|
|
|
originNode: React.ReactNode,
|
|
|
|
) => React.ReactNode | RcRenderedCell<T>;
|
2023-05-06 15:24:22 +08:00
|
|
|
onCell?: GetComponentProps<T>;
|
2017-11-21 13:48:37 +08:00
|
|
|
}
|
|
|
|
|
2019-11-15 14:35:25 +08:00
|
|
|
export type TransformColumns<RecordType> = (
|
|
|
|
columns: ColumnsType<RecordType>,
|
|
|
|
) => ColumnsType<RecordType>;
|
2017-11-21 13:48:37 +08:00
|
|
|
|
2019-11-15 14:35:25 +08:00
|
|
|
export interface TableCurrentDataSource<RecordType> {
|
|
|
|
currentDataSource: RecordType[];
|
2020-06-28 22:41:59 +08:00
|
|
|
action: TableAction;
|
2018-05-07 12:32:26 +08:00
|
|
|
}
|
|
|
|
|
2019-11-15 14:35:25 +08:00
|
|
|
export interface SorterResult<RecordType> {
|
|
|
|
column?: ColumnType<RecordType>;
|
|
|
|
order?: SortOrder;
|
2021-01-28 01:21:58 +08:00
|
|
|
field?: Key | readonly Key[];
|
2019-11-15 14:35:25 +08:00
|
|
|
columnKey?: Key;
|
2017-11-21 13:48:37 +08:00
|
|
|
}
|
|
|
|
|
2019-11-15 14:35:25 +08:00
|
|
|
export type GetPopupContainer = (triggerNode: HTMLElement) => HTMLElement;
|
2018-09-30 11:17:39 +08:00
|
|
|
|
2020-04-27 23:45:14 +08:00
|
|
|
type TablePaginationPosition =
|
|
|
|
| 'topLeft'
|
|
|
|
| 'topCenter'
|
|
|
|
| 'topRight'
|
|
|
|
| 'bottomLeft'
|
|
|
|
| 'bottomCenter'
|
2023-10-18 13:33:25 +08:00
|
|
|
| 'bottomRight'
|
|
|
|
| 'none';
|
2020-04-27 23:45:14 +08:00
|
|
|
|
|
|
|
export interface TablePaginationConfig extends PaginationProps {
|
|
|
|
position?: TablePaginationPosition[];
|
2019-11-15 14:35:25 +08:00
|
|
|
}
|