import { AffixProps } from '../affix'; import { LoadingProps } from '../loading'; import { TableConfig } from '../config-provider'; import { PaginationProps, PageInfo } from '../pagination'; import { TooltipProps } from '../tooltip'; import { CheckboxGroupValue } from '../checkbox'; import { SortableEvent, SortableOptions } from 'sortablejs'; import { CheckboxProps } from '../checkbox'; import { RadioProps } from '../radio'; import { PopupProps } from '../popup'; import { InputProps } from '../input'; import { ButtonProps } from '../button'; import { CheckboxGroupProps } from '../checkbox'; import { DialogProps } from '../dialog'; import { FormRule, AllValidateResult } from '../form'; import { TNode, OptionData, SizeEnum, ClassName, Styles, AttachNode, HTMLElementAttributes, ComponentType, TScroll, ComponentScrollToElementParams } from '../common'; export interface TdBaseTableProps { activeRowKeys?: Array; defaultActiveRowKeys?: Array; activeRowType?: 'single' | 'multiple'; allowResizeColumnWidth?: boolean; attach?: AttachNode; bordered?: boolean; bottomContent?: string | TNode; cellEmptyContent?: string | TNode>; columns?: Array>; data?: Array; disableDataPage?: boolean; disableSpaceInactiveRow?: boolean; empty?: string | TNode; firstFullRow?: string | TNode; fixedRows?: Array; footData?: Array; footerAffixProps?: Partial; footerAffixedBottom?: boolean | Partial; footerSummary?: string | TNode; headerAffixProps?: Partial; headerAffixedTop?: boolean | Partial; height?: string | number; horizontalScrollAffixedBottom?: boolean | Partial; hover?: boolean; keyboardRowHover?: boolean; lastFullRow?: string | TNode; lazyLoad?: boolean; loading?: boolean | TNode; loadingProps?: Partial; locale?: TableConfig; maxHeight?: string | number; pagination?: PaginationProps; paginationAffixedBottom?: boolean | Partial; resizable?: boolean; rowAttributes?: TableRowAttributes; rowClassName?: ClassName | ((params: RowClassNameParams) => ClassName); rowKey: string; rowspanAndColspan?: TableRowspanAndColspanFunc; rowspanAndColspanInFooter?: TableRowspanAndColspanFunc; scroll?: TScroll; showHeader?: boolean; size?: SizeEnum; stripe?: boolean; tableContentWidth?: string; tableLayout?: 'auto' | 'fixed'; topContent?: string | TNode; verticalAlign?: 'top' | 'middle' | 'bottom'; onActiveChange?: (activeRowKeys: Array, context: ActiveChangeContext) => void; onActiveRowAction?: (context: ActiveRowActionContext) => void; onCellClick?: (context: BaseTableCellEventContext) => void; onColumnResizeChange?: (context: { columnsWidth: { [colKey: string]: number; }; }) => void; onPageChange?: (pageInfo: PageInfo, newDataSource: Array) => void; onRowClick?: (context: RowEventContext) => void; onRowDblclick?: (context: RowEventContext) => void; onRowMousedown?: (context: RowEventContext) => void; onRowMouseenter?: (context: RowEventContext) => void; onRowMouseleave?: (context: RowEventContext) => void; onRowMouseover?: (context: RowEventContext) => void; onRowMouseup?: (context: RowEventContext) => void; onScroll?: (params: { e: WheelEvent; }) => void; onScrollX?: (params: { e: WheelEvent; }) => void; onScrollY?: (params: { e: WheelEvent; }) => void; } export interface BaseTableInstanceFunctions { refreshTable: () => void; scrollColumnIntoView: (colKey: string) => void; scrollToElement: (params: ComponentScrollToElementParams) => void; } export interface BaseTableCol { align?: 'left' | 'right' | 'center'; attrs?: BaseTableColumnAttributes; cell?: string | TNode>; children?: Array>; className?: TableColumnClassName | TableColumnClassName[]; colKey?: string; colspan?: number; ellipsis?: boolean | TNode> | TooltipProps | { props: TooltipProps; content: TNode>; }; ellipsisTitle?: boolean | TNode> | TooltipProps | { props: TooltipProps; content: TNode>; }; fixed?: 'left' | 'right'; foot?: string | TNode<{ col: BaseTableCol; colIndex: number; }>; minWidth?: string | number; render?: TNode>; resizable?: boolean; resize?: TableColumnResizeConfig; stopPropagation?: boolean; thClassName?: TableColumnClassName | TableColumnClassName[]; title?: string | TNode<{ col: BaseTableCol; colIndex: number; }>; width?: string | number; } export interface TdPrimaryTableProps extends Omit, 'columns' | 'onCellClick'> { asyncLoading?: 'loading' | 'load-more' | TNode; columnController?: TableColumnController; columnControllerVisible?: boolean; defaultColumnControllerVisible?: boolean; columns?: Array>; displayColumns?: CheckboxGroupValue; defaultDisplayColumns?: CheckboxGroupValue; dragSort?: 'row' | 'row-handler' | 'col' | 'row-handler-col' | 'drag-col'; dragSortOptions?: SortableOptions; editableCellState?: EditableCellType; editableRowKeys?: Array; expandIcon?: boolean | TNode>; expandOnRowClick?: boolean; expandedRow?: TNode>; expandedRowKeys?: Array; defaultExpandedRowKeys?: Array; filterIcon?: TNode<{ col: PrimaryTableCol; colIndex: number; }>; filterRow?: string | TNode; filterValue?: FilterValue; defaultFilterValue?: FilterValue; hideSortTips?: boolean; indeterminateSelectedRowKeys?: Array; multipleSort?: boolean; reserveSelectedRowOnPaginate?: boolean; rowSelectionAllowUncheck?: boolean; rowSelectionType?: 'single' | 'multiple'; selectOnRowClick?: boolean; selectedRowKeys?: Array; defaultSelectedRowKeys?: Array; showSortColumnBgColor?: boolean; sort?: TableSort; defaultSort?: TableSort; sortIcon?: TNode; sortOnRowDraggable?: boolean; onAsyncLoadingClick?: (context: { status: 'loading' | 'load-more'; }) => void; onCellClick?: (context: PrimaryTableCellEventContext) => void; onChange?: (data: TableChangeData, context: TableChangeContext) => void; onColumnChange?: (context: PrimaryTableColumnChange) => void; onColumnControllerVisibleChange?: (visible: boolean, context: { trigger: 'cancel' | 'confirm' | 'open'; }) => void; onDataChange?: (data: Array, context: TableDataChangeContext) => void; onDisplayColumnsChange?: (value: CheckboxGroupValue) => void; onDragSort?: (context: DragSortContext) => void; onExpandChange?: (expandedRowKeys: Array, options: ExpandOptions) => void; onFilterChange?: (filterValue: FilterValue, context: TableFilterChangeContext) => void; onRowEdit?: (context: PrimaryTableRowEditContext) => void; onRowValidate?: (context: PrimaryTableRowValidateContext) => void; onSelectChange?: (selectedRowKeys: Array, options: SelectOptions) => void; onSortChange?: (sort: TableSort, options: SortOptions) => void; onValidate?: (context: PrimaryTableValidateContext) => void; } export interface PrimaryTableInstanceFunctions { clearValidateData: () => void; validateRowData: (rowValue: any) => Promise<{ trigger: TableValidateTrigger; result: ErrorListObjectType[]; }>; validateTableCellData: () => Promise<{ result: TableErrorListMap; }>; validateTableData: () => Promise<{ result: TableErrorListMap; }>; } export interface PrimaryTableCol extends Omit { cell?: string | TNode>; checkProps?: CheckProps; children?: Array>; colKey?: string; disabled?: (options: { row: T; rowIndex: number; }) => boolean; edit?: TableEditableCellConfig; filter?: TableColumnFilter; render?: TNode>; sortType?: SortType; sorter?: boolean | SorterFun; title?: string | TNode<{ col: PrimaryTableCol; colIndex: number; }>; type?: 'single' | 'multiple'; } export interface TdEnhancedTableProps extends TdPrimaryTableProps { beforeDragSort?: (context: DragSortContext) => boolean; expandedTreeNodes?: Array; defaultExpandedTreeNodes?: Array; tree?: TableTreeConfig; treeExpandAndFoldIcon?: TNode<{ type: 'expand' | 'fold'; row: T; }>; onAbnormalDragSort?: (context: TableAbnormalDragSortContext) => void; onExpandedTreeNodesChange?: (expandedTreeNodes: Array, options: TableTreeNodeExpandOptions) => void; onTreeExpandChange?: (context: TableTreeExpandChangeContext) => void; } export interface EnhancedTableInstanceFunctions { appendTo: (key: TableRowValue, newData: T) => void; expandAll: () => void; foldAll: () => void; getData: (key: TableRowValue) => TableRowState; getTreeExpandedRow: (type: 'unique' | 'data' | 'all') => void; getTreeNode: () => T[]; insertAfter: (key: TableRowValue, newData: T) => void; insertBefore: (key: TableRowValue, newData: T) => void; remove: (key: TableRowValue) => void; removeChildren: (key: TableRowValue) => void; resetData: (newData: T[]) => void; setData: (key: TableRowValue, newRowData: T) => void; swapData: (params: SwapParams) => void; toggleExpandData: (p: { row: T; rowIndex: number; }) => void; } export interface TableRowState { disabled?: boolean; expandChildrenLength?: number; expanded: boolean; id: string | number; level?: number; parent?: TableRowState; path?: TableRowState[]; row: T; rowIndex: number; } export interface TableColumnFilter { attrs?: HTMLElementAttributes; classNames?: ClassName; component?: ComponentType; confirmEvents?: string[]; label?: string | TNode; list?: Array; popupProps?: PopupProps; props?: FilterProps; resetValue?: any; showConfirmAndReset?: boolean; style?: Styles; type?: FilterType; } export interface TableColumnController { buttonProps?: ButtonProps; checkboxProps?: CheckboxGroupProps; columnControllerBottomContent?: TNode; columnControllerTopContent?: TNode; dialogProps?: DialogProps; displayType?: 'fixed-width' | 'auto-width'; fields?: string[]; groupColumns?: TableColumnGroup[]; hideTriggerButton?: boolean; placement?: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right'; } export interface TableEditableCellConfig { abortEditOnEvent?: string[]; component?: ComponentType; defaultEditable?: boolean; keepEditMode?: boolean; on?: (context: TableEditableCellPropsParams) => { [eventName: string]: Function; }; onEdited?: (context: PrimaryTableOnEditedContext) => void; props?: TableEditableCellProps; rules?: TableEditableCellRules; showEditIcon?: boolean; validateTrigger?: 'exit' | 'change'; } export interface TableTreeConfig { checkStrictly?: boolean; childrenKey?: string; defaultExpandAll?: boolean; expandTreeNodeOnClick?: boolean; indent?: number; treeNodeColumnIndex?: number; } export type TableRowAttributes = HTMLElementAttributes | ((params: { row: T; rowIndex: number; type: 'body' | 'foot'; }) => HTMLElementAttributes) | Array>; export interface RowClassNameParams { row: T; rowIndex: number; rowKey?: string; type?: 'body' | 'foot'; } export type TableRowspanAndColspanFunc = (params: BaseTableCellParams) => RowspanColspan; export interface RowspanColspan { colspan?: number; rowspan?: number; } export interface ActiveChangeContext { activeRowList: Array<{ row: T; rowIndex: number; }>; currentRowData?: T; type: 'active' | 'inactive'; } export interface ActiveRowActionContext { action: ActiveRowActionType; activeRowList: Array<{ row: T; rowIndex: number; }>; } export type ActiveRowActionType = 'shift-area-selection' | 'space-one-selection' | 'clear' | 'select-all'; export interface BaseTableCellEventContext { row: T; col: BaseTableCol; rowIndex: number; colIndex: number; e: MouseEvent; } export interface RowEventContext { row: T; index: number; e: MouseEvent | KeyboardEvent; } export interface TableRowData { [key: string]: any; children?: TableRowData[]; } export type BaseTableColumnAttributes = { [key: string]: any; } | ((context: CellData) => { [key: string]: any; }); export interface BaseTableCellParams { row: T; rowIndex: number; col: BaseTableCol; colIndex: number; } export type TableColumnClassName = ClassName | ((context: CellData) => ClassName); export interface CellData extends BaseTableCellParams { type: 'th' | 'td'; } export interface BaseTableColParams { col: BaseTableCol; colIndex: number; } export interface BaseTableRenderParams extends BaseTableCellParams { type: RenderType; } export type RenderType = 'cell' | 'title'; export interface TableColumnResizeConfig { minWidth: number; maxWidth: number; } export type DataType = TableRowData; export type EditableCellType = (params: PrimaryTableCellParams) => boolean; export interface ExpandArrowRenderParams { row: T; index: number; } export interface TableExpandedRowParams { row: T; index: number; columns: PrimaryTableCol[] | BaseTableCol[]; } export type FilterValue = { [key: string]: any; }; export type TableSort = SortInfo | Array; export interface SortInfo { sortBy: string; descending: boolean; } export interface PrimaryTableCellEventContext { row: T; col: PrimaryTableCol; rowIndex: number; colIndex: number; e: MouseEvent; } export interface TableChangeData { sorter?: TableSort; filter?: FilterValue; pagination?: PaginationProps; } export interface TableChangeContext { trigger: TableChangeTrigger; currentData?: T[]; } export type TableChangeTrigger = 'filter' | 'sorter' | 'pagination'; export interface PrimaryTableColumnChange { columns?: CheckboxGroupValue; currentColumn?: PrimaryTableCol; type?: 'check' | 'uncheck'; e?: Event; } export interface TableDataChangeContext { trigger: 'sort'; } export interface DragSortContext { currentIndex: number; current: T; targetIndex: number; target: T; data: T[]; newData: T[]; currentData?: T[]; e: SortableEvent; sort: 'row' | 'col'; } export interface ExpandOptions { expandedRowData: Array; currentRowData: T; } export interface TableFilterChangeContext { col?: PrimaryTableCol; trigger: 'filter-change' | 'confirm' | 'reset' | 'clear'; } export type PrimaryTableRowEditContext = PrimaryTableCellParams & { value: any; editedRow: T; }; export type PrimaryTableRowValidateContext = { result: TableRowValidateResult[]; trigger: TableValidateTrigger; }; export type TableValidateTrigger = 'self' | 'parent'; export type TableRowValidateResult = PrimaryTableCellParams & { errorList: AllValidateResult[]; value: any; }; export interface SelectOptions { selectedRowData: Array; type: 'uncheck' | 'check'; currentRowKey?: string; currentRowData?: T; } export interface SortOptions { currentDataSource?: Array; col: PrimaryTableCol; } export interface PrimaryTableValidateContext { result: TableErrorListMap; } export type TableErrorListMap = { [key: string]: AllValidateResult[]; }; export type ErrorListObjectType = PrimaryTableRowEditContext & { errorList: AllValidateResult[]; }; export interface PrimaryTableCellParams { row: T; rowIndex: number; col: PrimaryTableCol; colIndex: number; } export type CheckProps = CheckboxProps | RadioProps | ((options: { row: T; rowIndex: number; }) => CheckboxProps | RadioProps); export interface PrimaryTableRenderParams extends PrimaryTableCellParams { type: RenderType; } export type SortType = 'desc' | 'asc' | 'all'; export type SorterFun = (a: T, b: T) => number; export interface TableAbnormalDragSortContext { code: number; reason: string; } export interface TableTreeNodeExpandOptions { row: T; rowIndex: number; rowState: TableRowState; type: 'fold' | 'expand'; trigger?: 'expand-fold-icon' | 'row-click' | 'default-expand-all' | 'expand-all' | 'fold-all'; } export interface TableTreeExpandChangeContext { row: T; rowIndex: number; rowState: TableRowState; trigger?: 'expand-fold-icon' | 'row-click'; } export type TableRowValue = string | number; export interface SwapParams { current: T; target: T; currentIndex: number; targetIndex: number; } export type FilterProps = RadioProps | CheckboxProps | InputProps | { [key: string]: any; }; export type FilterType = 'input' | 'single' | 'multiple'; export interface TableColumnGroup { label: string; value?: string | number; columns: string[]; } export type PrimaryTableOnEditedContext = PrimaryTableCellParams & { trigger: string; newRowData: T; }; export type TableEditableCellProps = TablePlainObject | ((params: TableEditableCellPropsParams) => TablePlainObject); export interface TableEditableCellPropsParams extends PrimaryTableCellParams { editedRow: T; updateEditedCellValue: (val: any | { rowValue?: string | number; isUpdateCurrentRow?: boolean; [key: string]: any; }) => void; } export interface TablePlainObject { [key: string]: any; } export type TableEditableCellRules = FormRule[] | ((params: PrimaryTableCellParams) => FormRule[]);