ant-design/components/table/interface.tsx

150 lines
4.3 KiB
TypeScript
Raw Normal View History

2019-11-25 15:16:59 +08:00
import { GetRowKey, ColumnType as RcColumnType, ExpandableConfig } from 'rc-table/lib/interface';
import { CheckboxProps } from '../checkbox';
import { PaginationConfig } from '../pagination';
2019-10-14 15:50:36 +08:00
export { GetRowKey, ExpandableConfig };
2019-08-05 18:38:10 +08:00
export type Key = React.Key;
2017-11-21 13:48:37 +08:00
export type RowSelectionType = 'checkbox' | 'radio';
2019-05-07 11:53:08 +08:00
export type SelectionItemSelectFn = (currentRowKeys: Key[]) => void;
2017-11-21 13:48:37 +08:00
export type ExpandType = null | 'row' | 'nest';
2017-11-21 13:48:37 +08:00
export interface TableLocale {
filterTitle?: string;
filterConfirm?: React.ReactNode;
filterReset?: React.ReactNode;
emptyText?: React.ReactNode | (() => React.ReactNode);
selectAll?: React.ReactNode;
selectInvert?: React.ReactNode;
selectionAll?: React.ReactNode;
2018-09-17 17:57:01 +08:00
sortTitle?: string;
expand?: string;
collapse?: string;
2017-11-21 13:48:37 +08:00
}
export type SortOrder = 'descend' | 'ascend' | null;
2018-05-07 12:32:26 +08:00
export type CompareFn<T> = (a: T, b: T, sortOrder?: SortOrder) => number;
export interface ColumnFilterItem {
text: React.ReactNode;
value: string;
children?: ColumnFilterItem[];
}
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 }[];
filters?: Record<string, string[]>;
}
export type ColumnTitle<RecordType> =
| React.ReactNode
| ((props: ColumnTitleProps<RecordType>) => React.ReactNode);
export interface FilterDropdownProps {
prefixCls: string;
setSelectedKeys: (selectedKeys: string[]) => void;
selectedKeys: React.Key[];
confirm: () => void;
2019-11-25 15:16:59 +08:00
clearFilters?: () => void;
filters?: ColumnFilterItem[];
visible: boolean;
}
export interface ColumnType<RecordType> extends RcColumnType<RecordType> {
title?: ColumnTitle<RecordType>;
// Sorter
sorter?:
| boolean
| CompareFn<RecordType>
| {
compare: CompareFn<RecordType>;
/** Config multiple sorter order priority */
multiple: number;
};
sortOrder?: SortOrder;
defaultSortOrder?: SortOrder;
2019-01-08 17:27:41 +08:00
sortDirections?: SortOrder[];
2019-10-22 11:54:03 +08:00
// Filter
filters?: ColumnFilterItem[];
filterDropdown?: React.ReactNode | ((props: FilterDropdownProps) => React.ReactNode);
filterMultiple?: boolean;
2019-11-25 15:16:59 +08:00
filteredValue?: Key[] | null;
defaultFilteredValue?: Key[] | null;
filterIcon?: React.ReactNode | ((filtered: boolean) => React.ReactNode);
onFilter?: (value: any, record: RecordType) => boolean;
filterDropdownVisible?: boolean;
onFilterDropdownVisibleChange?: (visible: boolean) => void;
2017-11-21 13:48:37 +08:00
}
export interface ColumnGroupType<RecordType> extends ColumnType<RecordType> {
2019-11-25 15:16:59 +08:00
children: ColumnsType<RecordType>;
}
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;
onSelect?: SelectionItemSelectFn;
2017-11-21 13:48:37 +08:00
}
export type SelectionSelectFn<T> = (
record: T,
selected: boolean,
selectedRows: Object[],
nativeEvent: Event,
) => void;
2017-11-21 13:48:37 +08:00
export interface TableRowSelection<T> {
2017-11-21 13:48:37 +08:00
type?: RowSelectionType;
selectedRowKeys?: Key[];
onChange?: (selectedRowKeys: Key[], selectedRows: T[]) => void;
getCheckboxProps?: (record: T) => Partial<CheckboxProps>;
onSelect?: SelectionSelectFn<T>;
onSelectMultiple?: (selected: boolean, selectedRows: T[], changeRows: T[]) => void;
/** @deprecated This function is meaningless and should use `onChange` instead */
onSelectAll?: (selected: boolean, selectedRows: T[], changeRows: T[]) => void;
/** @deprecated This function is meaningless and should use `onChange` instead */
onSelectInvert?: (selectedRowKeys: Key[]) => void;
selections?: SelectionItem[] | boolean;
hideDefaultSelections?: boolean;
fixed?: boolean;
columnWidth?: string | number;
columnTitle?: string | React.ReactNode;
2017-11-21 13:48:37 +08:00
}
export type TransformColumns<RecordType> = (
columns: ColumnsType<RecordType>,
) => ColumnsType<RecordType>;
2017-11-21 13:48:37 +08:00
export interface TableCurrentDataSource<RecordType> {
currentDataSource: RecordType[];
2018-05-07 12:32:26 +08:00
}
export interface SorterResult<RecordType> {
column?: ColumnType<RecordType>;
order?: SortOrder;
field?: Key | Key[];
columnKey?: Key;
2017-11-21 13:48:37 +08:00
}
export type GetPopupContainer = (triggerNode: HTMLElement) => HTMLElement;
export interface TablePaginationConfig extends PaginationConfig {
position?: 'top' | 'bottom' | 'both';
}