types: add datasource generics type in Table (#3603)

This commit is contained in:
feng zhi hao 2016-10-26 18:26:26 +08:00 committed by 偏右
parent a62c958a15
commit 90fbd4da51

View File

@ -34,22 +34,22 @@ const defaultPagination = {
onShowSizeChange: noop, onShowSizeChange: noop,
}; };
export interface TableRowSelection { export interface TableRowSelection<T> {
type?: 'checkbox' | 'radio'; type?: 'checkbox' | 'radio';
selectedRowKeys?: string[]; selectedRowKeys?: string[];
onChange?: (selectedRowKeys: string[], selectedRows: Object[]) => any; onChange?: (selectedRowKeys: string[], selectedRows: Object[]) => any;
getCheckboxProps?: (record: Object) => Object; getCheckboxProps?: (record: T) => Object;
onSelect?: (record: Object, selected: boolean, selectedRows: Object[]) => any; onSelect?: (record: T, selected: boolean, selectedRows: Object[]) => any;
onSelectAll?: (selected: boolean, selectedRows: Object[], changeRows: Object[]) => any; onSelectAll?: (selected: boolean, selectedRows: Object[], changeRows: Object[]) => any;
} }
export interface TableColumnConfig { export interface TableColumnConfig<T> {
title?: React.ReactNode; title?: React.ReactNode;
key?: string; key?: string;
dataIndex?: string; dataIndex?: string;
render?: (text: any, record: Object, index: number) => React.ReactNode; render?: (text: any, record: T, index: number) => React.ReactNode;
filters?: { text: string; value: string }[]; filters?: { text: string; value: string }[];
onFilter?: (value: any, record: Object) => boolean; onFilter?: (value: any, record: T) => boolean;
filterMultiple?: boolean; filterMultiple?: boolean;
filterDropdown?: React.ReactNode; filterDropdown?: React.ReactNode;
sorter?: boolean | ((a: any, b: any) => number); sorter?: boolean | ((a: any, b: any) => number);
@ -61,16 +61,16 @@ export interface TableColumnConfig {
sortOrder?: boolean | ('ascend' | 'descend'); sortOrder?: boolean | ('ascend' | 'descend');
} }
export interface TableProps { export interface TableProps<T> {
prefixCls?: string; prefixCls?: string;
dropdownPrefixCls?: string; dropdownPrefixCls?: string;
rowSelection?: TableRowSelection; rowSelection?: TableRowSelection<T>;
pagination?: PaginationProps | boolean; pagination?: PaginationProps | boolean;
size?: 'default' | 'small'; size?: 'default' | 'small';
dataSource?: Object[]; dataSource?: T[];
columns: TableColumnConfig[]; columns: TableColumnConfig<T>[];
rowKey?: string | ((record: Object, index: number) => string); rowKey?: string | ((record: T, index: number) => string);
rowClassName?: (record: Object, index: number) => string; rowClassName?: (record: T, index: number) => string;
expandedRowRender?: any; expandedRowRender?: any;
defaultExpandedRowKeys?: string[]; defaultExpandedRowKeys?: string[];
expandedRowKeys?: string[]; expandedRowKeys?: string[];
@ -80,7 +80,7 @@ export interface TableProps {
loading?: boolean; loading?: boolean;
locale?: Object; locale?: Object;
indentSize?: number; indentSize?: number;
onRowClick?: (record: Object, index: number) => any; onRowClick?: (record: T, index: number) => any;
useFixedHeader?: boolean; useFixedHeader?: boolean;
bordered?: boolean; bordered?: boolean;
showHeader?: boolean; showHeader?: boolean;
@ -98,7 +98,7 @@ export interface TableContext {
}; };
} }
export default class Table extends React.Component<TableProps, any> { export default class Table<T> extends React.Component<TableProps<T>, any> {
static propTypes = { static propTypes = {
dataSource: React.PropTypes.array, dataSource: React.PropTypes.array,
columns: React.PropTypes.array.isRequired, columns: React.PropTypes.array.isRequired,