import React, { ComponentProps, ReactElement, ReactNode, RefObject } from 'react'; import { DivProps, Id, Obj, SlotsAndProps, ToRequired } from '../../types'; import { SelectionContextProps } from '../selectionContext'; import { PaginationProps } from '../pagination'; import { TableProps } from '../table'; import { CheckboxProps } from '../checkbox'; import { RadioProps } from '../radio'; import { FieldPath } from '../../utils'; import { FormProps, FormValue } from '../form'; import { FilterControlProps, FilterOptionsProps } from './filterBubbleContent'; import { BubbleProps } from '../bubble'; export type RowType = Obj; export interface ColumnType extends Omit, 'key' | 'ref' | 'title' | 'children'>, Omit, 'key' | 'ref' | 'title' | 'children'> { title?: ReactNode; /** 当`title`非字符串时,可指定该属性,用于渲染在 “列设置” 中 */ titleText?: string; /** 若不指定key,默认使用{@link field}作为key */ key?: string | number; children?: ColumnType[]; /** 是否将列固定在左侧或右侧 */ sticky?: 'left' | 'right'; /** 指定children后,下列属性均不生效 */ field?: FieldPath; render?(row: R, index?: number, rows?: R[]): ReactNode; /** * @enum true 使用服务端排序,组件只做样式处理,不做数据排序处理; * @enum function 本地排序需指定 `正序` 的排序方法,倒序会自动处理 */ sorter?: boolean | ((a: R, b: R) => number); /** * @enum true 不会弹出气泡框,需配合{@link DataGridBaseProp['onFilterClick']}实现筛选逻辑 * @enum FilterOptionsProps 传递至`OptionsBase`组件 * @example FilterOptionsProps * { * filter: { * options: [ * {value: '1', label: '选项1‘} * ] * } * } * @enum FilterControlProps 自定义渲染气泡内容 * @example FilterControlProps * { * filter: { * control: * } * } */ filter?: boolean | FilterOptionsProps | FilterControlProps; /** @private 内部使用,在{@link useDataGridColumns}内赋值 */ _key?: Id; /** @private 内部使用,在{@link DataGridHead}内计算 */ _negativeRowSpan?: number; } interface DataGridSharedProps extends SlotsAndProps<{ container: ComponentProps<'div'>; tr: ComponentProps<'tr'>; }> { rowProps?(row: R, index: number, rows: R[]): ComponentProps<'tr'>; /** 数据的主键名,默认为`id` */ primaryKey?: keyof R; /** * 当数据中存在该字段,则会渲染可展开的子行,默认为`null`,表示不使用子行功能, * children允许的值类型: * @types {R[] | ReactNode | ((parent: R, expanded: boolean) => ReactNode)} */ childrenKey?: keyof R | null; /** 点击行时是否触发选中,默认为`true` */ clickRowToSelect?: boolean; /** 子行缩进,默认为`24` */ indent?: number; renderExpandIcon?(key: Id, isExpand: boolean, expanded: Id[]): ReactNode; } export type OrderType = 'ascend' | 'descend'; export interface DataGridBaseProps extends DataGridSharedProps, Omit { columns?: (ColumnType | symbol)[]; rows?: R[]; filterProps?: FormProps; initialFilterValue?: FormValue; filterBubbleProps?: BubbleProps; onFilter?(filterValue: FormValue): void; onFilterClick?(column: Id, e: React.MouseEvent): void; /** 若需要本地筛选,必须指定该方法 */ filterPredicate?(row: R, index: number, filterValue: FormValue): any; defaultOrderColumn?: Id; orderColumn?: Id; defaultOrderType?: OrderType; orderType?: OrderType; onOrderChange?(orderColumn: Id, orderType: OrderType): void; selectable?: boolean; /** * 行之间的关系 * @enum {'dependent'}:会自动判断子父行的选中关系。 * @enum {'standalone'}:所有行相互独立 * 默认为"dependent" */ relation?: SelectionContextProps['relation']; integration?: SelectionContextProps['integration']; /** 是否允许全选,默认为true */ allowSelectAll?: boolean; selectorProps?(row: R, index: number, rows: R[]): CheckboxProps | RadioProps; onToggle?(checked: boolean, value: Id, option?: R): void; defaultExpanded?: Id[]; expanded?: Id[]; onExpandedChange?(expanded: Id[], key: Id, isExpand: boolean): void; /** 是否内置翻页,默认为true */ paginatable?: boolean; paginationProps?: PaginationProps; renderPagination?(props: PaginationProps): ReactNode; loading?: boolean; emptyPlaceholder?: ReactNode; /** 是否可以拖拽调整列宽,默认为`false`,开启此功能后表头分组功能将失效 */ columnResizable?: boolean; /** 传递给的属性 */ size?: TableProps['size']; bordered?: TableProps['bordered']; striped?: TableProps['striped']; tableProps?: TableProps; /** @private 内部使用,在内渲染时,禁用Form标签 */ _noRenderFormTag?: boolean; } export interface DataGridSingleProps extends DataGridBaseProps { multiple?: false; defaultValue?: V; value?: V; onChange?(value: V): void; } export interface DataGridMultipleProps extends DataGridBaseProps { multiple: true; defaultValue?: V[]; value?: V[]; onChange?(value: V[]): void; } export type DataGridProps = DataGridSingleProps | DataGridMultipleProps; interface IDataGridContext extends ToRequired, 'primaryKey' | 'childrenKey' | 'clickRowToSelect' | 'indent'> { expandedSet: Set; flattedColumns: (symbol | ColumnType)[] | undefined; toggleExpanded(key: Id): void; theadRef: RefObject; } export declare function useDataGridContext(): IDataGridContext; export declare const DataGrid: { (props: DataGridProps): ReactElement; EXPAND_COLUMN: symbol; SELECT_COLUMN: symbol; }; export {};