import { type SizeType } from '../config-provider'; import React, { ReactNode, CSSProperties } from 'react'; import { PaginationProps } from '../pagination/pagination'; import { SpinProps } from '../spin'; import { TriggerProps } from '../trigger'; import { TooltipProps } from '../tooltip'; import { AvailableVirtualListProps, VirtualListHandle } from '../_class/virtual-list'; export declare type RowCallbackProps = { onClick?: (event: any) => void; onDoubleClick?: (event: any) => void; onContextMenu?: (event: any) => void; onMouseEnter?: (event: any) => void; onMouseLeave?: (event: any) => void; onHandleSave?: (row: any) => void; [name: string]: any; }; export declare type SorterFn = (a: any, b: any) => number; /** * @title Table */ export interface TableProps { style?: CSSProperties; className?: string | string[]; /** * 自适应高度,一屏展示 */ autoFillHeight?: boolean; /** * 自动计算宽度,如果有传入width,以传入为准 */ autoFillWidth?: boolean; /** * 是否允许拖拽表头列边界调整列宽。 * @defaultValue false */ resizable?: boolean; /** * 拖拽调整列宽时的最小宽度。 * @defaultValue 40 */ columnResizeMinWidth?: number; /** * 拖拽调整列宽时触发。 */ onColumnResize?: (width: number, column: ColumnProps, index: number) => void; /** * 表格的 `table-layout` 属性设置为 `fixed`,设置为 `fixed` 后,表格的宽度不会被内容撑开超出 100%。 */ tableLayoutFixed?: boolean; /** * 表格行 key 的取值字段 * @defaultValue key */ rowKey?: Key | ((record: T) => Key); /** * 列描述数据对象的数组 */ columns?: ColumnProps[]; /** * 覆盖原生表格标签 */ components?: ComponentsProps; /** * 表格数据 */ data?: T[]; /** * 边框设置 * @defaultValue true */ border?: boolean | { wrapper?: boolean; headerCell?: boolean; bodyCell?: boolean; cell?: boolean; }; /** * 是否显示单元格边框,作用等同于 `border={{ cell: true }}` */ bordered?: boolean; /** * 是否开启鼠标悬浮效果 * @defaultValue true */ hover?: boolean; /** * 默认展开所有可展开的行 */ defaultExpandAllRows?: boolean; /** * 展开的行(受控) */ expandedRowKeys?: (string | number)[]; /** * 默认展开的行 */ defaultExpandedRowKeys?: (string | number)[]; /** * 点击展开额外的行,渲染函数。返回值为 `null` 时,不会渲染展开按钮 */ expandedRowRender?: (record: T, index: number) => ReactNode; /** * 自定义展开/关闭列的图标,宽度,标题,具体用法看[这个例子](/react/components/table#定制展开参数) */ expandProps?: ExpandProps; /** * 点击展开的回调 */ onExpand?: (record: T, expanded: boolean) => void; /** * 点击展开时触发,参数为展开行数组 */ onExpandedRowsChange?: (expandedRows: (string | number)[]) => void; /** * 表格是否在加载中 */ loading?: boolean | SpinProps; /** * 没有数据的时候显示的元素 */ noDataElement?: string | ReactNode; /** * 是否显示表头 * @defaultValue true */ showHeader?: boolean; /** * @zh * 表头是否显示下一次排序的 tooltip 提示。可以设置对象,可以传 `Tooltip` 组件的所有参数。 * @defaultValue true */ showSorterTooltip?: boolean | TooltipProps; /** * 是否开启斑马纹 */ stripe?: boolean; /** * 表格尺寸,分为 默认,`默认` `中` `小` `迷你` 四个尺寸 */ size?: SizeType; /** * 分页、排序、筛选时的回调 */ onChange?: (pagination: PaginationProps, sorter: SorterInfo | SorterInfo[], filters: Partial>, extra: { currentData: T[]; currentAllData: T[]; action: 'paginate' | 'sort' | 'filter'; }) => void; /** * 分页器设置,参考[Pagination组件](/react/components/pagination),设置 `false` 不展示分页 */ pagination?: PaginationProps | boolean; /** * 自定义分页渲染。 */ renderPagination?: (paginationNode?: ReactNode) => ReactNode; /** * @zh * 设置x轴或y轴的滚动。`x` 设置为 `true`,会给 table 添加 `table-layout: fixed` 以及给父元素添加 `overflow: auto`。 * `y` 设置为 `true`,表头和表身会分离,放在两个 table 中 */ scroll?: { x?: number | string | boolean; y?: number | string | boolean; }; /** * 表格行的类名 */ rowClassName?: (record: T, index: number) => string; /** * 设置表格行是否可选,选中事件等。[配置项](#rowselection) */ rowSelection?: RowSelectionProps; /** * 设置表头行单元格的各项事件回调 */ onHeaderRow?: (columns: ColumnProps[], index: number) => RowCallbackProps; /** * 设置表格行的各项事件回调 */ onRow?: (record: T, index: number) => RowCallbackProps; prefixCls?: string; /** * 当单元格内容为空时,显示占位符,优先级低于 `column.placeholder`。 */ placeholder?: ReactNode; /** * 设置分页器的位置,有六个方位 `右下` `左下` `右上` `左上` `上中` `下中` * @defaultValue br */ pagePosition?: 'br' | 'bl' | 'tr' | 'tl' | 'topCenter' | 'bottomCenter'; /** * 树形数据在 `data` 中的字段名,默认是 `children` * @defaultValue children */ childrenColumnName?: string; /** * 树形数据每个层级向左偏移的像素 * @defaultValue 15 */ indentSize?: number; /** * 表格尾部 */ footer?: (currentPageDate: any) => ReactNode; /** * @zh * 表格开启虚拟滚动,用于处理大数据场景。( 注意:虚拟滚动会自动关闭对树形数据的支持 ) */ virtualized?: boolean; /** * @zh * 用于配置虚拟滚动。 */ virtualListProps?: AvailableVirtualListProps; /** * 总结栏 */ summary?: (currentData?: T[]) => ReactNode; } /** * @title RowSelection * * `` 参数 `rowSelection` 的详细参数。 */ export interface RowSelectionProps { /** * 多选模式下是否开启全选功能 */ checkAll?: boolean; /** * 设置为 `false` 的时候父子选择会自动关联。 * @defaultValue true */ checkStrictly?: boolean; /** * 多选模式下的复选框是否跨分页,只在非受控模式下生效。配合 preserveSelectedRowKeys: true 使用,可在受控模式下生效。 */ checkCrossPage?: boolean; /** * 自定义列表选择的标题 */ columnTitle?: string | ReactNode; /** * 选择框列的宽度 */ columnWidth?: number; /** * 选择框的属性配置 */ checkboxProps?: (record: T) => { [key: string]: any; }; /** * 是否固定选择列到左边 */ fixed?: boolean; /** * 单选或多选的选中项发生改变时的回调 */ onChange?: (selectedRowKeys: (string | number)[], selectedRows: T[]) => void; /** * 用户手动选择/取消选择的回调 * @en Callback for user manual selection/deselection * @version 2.22.0 */ onSelect?: (selected: boolean, record: T, selectedRows: T[]) => void; /** * 用户手动选择/取消选择所有行的回调 */ onSelectAll?: (selected: boolean, selectedRows: any) => void; /** * 在数据项被删除时仍然保留选项的 `key` */ preserveSelectedRowKeys?: boolean; /** * 定制复选框,用法与 `column.render` 相同。 */ renderCell?: (originNode: any, checked: boolean, record: T) => ReactNode; /** * Table选中的项,(受控模式,需要跟 `onChange` 配合使用) */ selectedRowKeys?: (string | number)[]; /** * 多选或者单选 */ type?: 'checkbox' | 'radio'; } /** * @title ExpandProps * * `
` 参数 `expandProps` 的详细参数。 */ export interface ExpandProps { /** * 定制展开按钮的图标 */ icon?: (props: { expanded: boolean; record: Record; }) => ReactNode; /** * 展开按钮列的宽度 */ width?: number; /** * 展开按钮列的表头标题 */ columnTitle?: ReactNode; /** * @zh * 是否允许行展开。如果不指定该参数,会以 expandedRowRender 是否有返回值决定。当出现性能问题时,建议使用 rowExpandable。 */ rowExpandable?: (record: T) => boolean; /** * 支持通过点击行来展开 */ expandRowByClick?: boolean; /** * 树形数据时,只有 `children` 是数组且长度大于 1 才显示展开图标。 * @defaultValue true */ strictTreeData?: boolean; } /** * @title Column * * 列描述数据对象,是 `columns` 中的一项。 */ export interface ColumnProps { /** * 列的类名 */ className?: string | string[]; /** * 设置列的对齐方式 * @defaultValue left */ align?: 'left' | 'center' | 'right'; /** * 单元格内容超出长度后,是否自动省略,显示 `...`。设置这个属性后,table 的 `table-layout` 将自动变成 `fixed`。 */ ellipsis?: boolean; /** * 表头单元格自定义样式 */ headerCellStyle?: CSSProperties; /** * 表身单元格自定义样式 */ bodyCellStyle?: CSSProperties; cellStyle?: CSSProperties; /** * 列标题 */ title: React.ReactNode; /** * 列宽度 */ width?: number | string; /** * 是否允许当前列拖拽调整宽度。需要配合 Table 的 `resizable` 使用。 * @defaultValue true */ resizable?: boolean; /** * @zh * 列数据在数据项中对应的 `key`,用于取值显示,支持 `a[0].b.c[1]` 的嵌套写法, * 详情看 [lodash.get](https://www.npmjs.com/package/lodash.get)。 */ dataIndex?: string; /** * React的 key值,如果不指定,默认取 `dataIndex` 的值 */ key?: string | number; /** * 自定义单元格显示的内容 */ render?: (col: any, item: T, index: number) => any; /** * 当单元格内容为空时,显示占位符,优先级低于 `render`。 */ placeholder?: ReactNode; /** * 排序函数,如果想要服务端排序或者添加更多自定义操作,设置为true,利用`onChange`函数进行自定义排序 */ sorter?: SorterFn | boolean | { compare?: SorterFn; multiple?: number; }; /** * 筛选项,需要配合 `onFilter` 或者 `onChange` 使用 * @defaultValue [] */ filters?: { text?: ReactNode; value?: any; [key: string]: any; }[]; /** * 默认筛选条件 */ defaultFilters?: string[]; /** * 默认排序方式 */ defaultSortOrder?: 'ascend' | 'descend'; /** * 筛选的受控属性,值为筛选的 value 数组 */ filteredValue?: string[]; /** * 排序的受控属性,可以控制列的排序,可设置为 `ascend` `descend` */ sortOrder?: 'ascend' | 'descend'; /** * 支持的排序方式。 * @defaultValue ['ascend','descend'] */ sortDirections?: Array<'ascend' | 'descend'>; /** * 是否可以筛选多项 * @defaultValue true */ filterMultiple?: boolean; /** * 自定义筛选图标。 */ filterIcon?: ReactNode; /** * 自定义筛选框。 */ filterDropdown?: (props: { filterKeys?: string[]; setFilterKeys?: (filterKeys: string[], callback?: Function) => void; confirm?: Function; }) => ReactNode; /** * 配置筛选弹出框的一些属性。 */ filterDropdownProps?: { triggerProps?: TriggerProps; }; /** * 筛选框打开关闭的回调 */ onFilterDropdownVisibleChange?: (visible: boolean) => void; /** * 筛选函数,配合`filters` */ onFilter?: (value: any, row: any) => any; /** * 固定头和列到左边或者右边 */ fixed?: 'left' | 'right'; /** * 设置头部单元格的各项事件回调 */ onHeaderCell?: (column: any, index: any) => RowCallbackProps; /** * 设置表身单元格的各项事件回调 */ onCell?: (record: any, index: any) => RowCallbackProps; children?: ColumnProps[]; rowSpan?: number; colSpan?: number; headerCellProps?: RowCallbackProps; editable?: boolean; prefixCls?: string; currentFilters?: { [key: string]: any; }; components?: ComponentsProps; columnFixedStyle?: CSSProperties; column?: any; [key: string]: any; } export declare type InternalColumnProps = ColumnProps & { $$isOperation?: boolean; $$isFirstColumn?: boolean; $$columnIndex?: number | number[]; node?: ReactNode; }; export interface ColumnComponentProps extends ColumnProps { onSort: (direction: string | undefined, field: string | number) => void; onHandleFilter: (column: Record, filter: Record) => void; onHandleFilterReset: (column: { [key: string]: any; }) => void; onColumnResizeStart?: (widths: Record) => void; onColumnResize?: (width: number, column: ColumnProps, index: number) => void; currentSorter?: SorterInfo; currentFilter?: { [key: string]: any; }; _key?: string | number; showSorterTooltip?: boolean | TooltipProps; index?: number; tableResizable?: boolean; columnResizeMinWidth?: number; } export declare type ComponentsProps = { table?: any; header?: { operations?: (nodes: { selectionNode?: ReactNode; expandNode?: ReactNode; }) => { name?: string; node?: ReactNode; width?: number; }[]; wrapper?: any; thead?: any; row?: any; th?: any; cell?: any; }; body?: { operations?: (nodes: { selectionNode?: ReactNode; expandNode?: ReactNode; }) => { name?: string; node?: ReactNode | ((record: any) => ReactNode); width?: number; }[]; wrapper?: any; tbody?: any; row?: any; td?: any; cell?: any; }; }; export interface TheadProps { expandedRowRender?: (record: T, index: number) => ReactNode; onCheckAll: (_: any, e: any) => void; onSort: (direction: any, field: any) => void; data: T[]; onHandleFilter: (column: any, filter: any) => void; onHandleFilterReset: (filter: any) => void; currentSorter: SorterInfo; activeSorters: SorterInfo[]; selectedRowKeys: (string | number)[]; onHeaderRow?: (columns: any, index: number) => RowCallbackProps; prefixCls?: string; rowSelection?: RowSelectionProps; columnTitle?: string | ReactNode; currentFilters?: Partial>; rowKey?: TableProps['rowKey']; components?: ComponentsProps; expandProps?: ExpandProps; allSelectedRowKeys?: (string | number)[]; groupColumns?: InternalColumnProps[][]; stickyOffsets?: number[]; groupStickyClassNames?: string[][]; showSorterTooltip?: boolean | TooltipProps; resizable?: boolean; columnResizeMinWidth?: number; onColumnResizeStart?: (widths: Record) => void; onColumnResize?: (width: number, column: ColumnProps, index: number) => void; } export declare type GetRowKeyType = (record: T) => string; declare type Key = string | number; export interface TbodyProps { data: T[]; selectedRowKeys: Key[]; indeterminateKeys: Key[]; components?: ComponentsProps; expandedRowKeys: Key[]; columns: InternalColumnProps[]; noDataElement?: string | ReactNode; onCheck: (checked: boolean, record: any) => void; onCheckRadio: (key: any, record: any) => void; onClickExpandBtn: (key: Key) => void; pagination?: PaginationProps | boolean; scroll?: { x?: number | string | boolean; y?: number | string | boolean; }; expandedRowRender?: (record: T, index: number) => ReactNode; rowClassName?: (record: T, index: number) => string; onRow?: (record: T, index: number) => RowCallbackProps; prefixCls?: string; rowSelection?: RowSelectionProps; expandProps?: ExpandProps; childrenColumnName?: string; indentSize?: number; hasFixedColumn?: boolean; tableViewWidth?: number; currentSorter?: SorterInfo; activeSorters?: SorterInfo[]; virtualized?: boolean; virtualListProps?: AvailableVirtualListProps; stickyOffsets?: number[]; stickyClassNames?: string[]; getRowKey?: GetRowKeyType; placeholder?: ReactNode; saveVirtualListRef?: (ref: VirtualListHandle) => void; saveRef?: (ref: HTMLElement | HTMLDivElement) => void; } export interface TfootProps { prefixCls?: string; summary?: (currentData?: T[]) => ReactNode; data?: T[]; columns?: InternalColumnProps[]; stickyOffsets?: number[]; stickyClassNames?: string[]; } export declare type SortDirection = 'descend' | 'ascend'; export interface SorterResult { direction?: SortDirection; field?: string; } export interface SorterInfo { direction?: SortDirection; field?: string | number; sorterFn?: SorterFn; priority?: number; } export interface SummaryProps { fixed?: 'top' | 'bottom'; children?: ReactNode; } export {};