diff --git a/components/lib/datatable/datatable.d.ts b/components/lib/datatable/datatable.d.ts index dea232e1a8..1adc7c2459 100644 --- a/components/lib/datatable/datatable.d.ts +++ b/components/lib/datatable/datatable.d.ts @@ -1,15 +1,15 @@ import * as React from 'react'; -import { Column, ColumnFilterMatchModeType } from '../column'; +import { Column, ColumnFilterMatchModeType, ColumnProps } from '../column'; import { PaginatorTemplate } from '../paginator'; import { VirtualScroller, VirtualScrollerProps } from '../virtualscroller/virtualscroller'; -type DataTableHeaderTemplateType = React.ReactNode | ((options: DataTableHeaderTemplateOptions) => React.ReactNode); +type DataTableHeaderTemplateType = React.ReactNode | ((options: DataTableHeaderTemplateOptions) => React.ReactNode); -type DataTableFooterTemplateType = React.ReactNode | ((options: DataTableFooterTemplateOptions) => React.ReactNode); +type DataTableFooterTemplateType = React.ReactNode | ((options: DataTableFooterTemplateOptions) => React.ReactNode); -type DataTableRowGroupHeaderTemplateType = React.ReactNode | ((data: any, options: DataTableRowGroupHeaderTemplateOptions) => React.ReactNode); +type DataTableRowGroupHeaderTemplateType = React.ReactNode | ((data: any, options: DataTableRowGroupHeaderTemplateOptions) => React.ReactNode); -type DataTableRowGroupFooterTemplateType = React.ReactNode | ((data: any, options: DataTableRowGroupFooterTemplateOptions) => React.ReactNode); +type DataTableRowGroupFooterTemplateType = React.ReactNode | ((data: any, options: DataTableRowGroupFooterTemplateOptions) => React.ReactNode); type DataTablePaginatorPositionType = 'top' | 'bottom' | 'both'; @@ -45,19 +45,19 @@ type DataTableSizeType = 'small' | 'normal' | 'large'; type DataTableScrollDirectionType = 'vertical' | 'horizontal' | 'both'; -interface DataTableHeaderTemplateOptions { - props: DataTableProps; +interface DataTableHeaderTemplateOptions { + props: DataTableProps; } -interface DataTableFooterTemplateOptions extends DataTableHeaderTemplateOptions {} +interface DataTableFooterTemplateOptions extends DataTableHeaderTemplateOptions {} -interface DataTableRowGroupHeaderTemplateOptions { +interface DataTableRowGroupHeaderTemplateOptions { index: number; - props: DataTableProps; + props: DataTableProps; customRendering: boolean; } -interface DataTableRowGroupFooterTemplateOptions extends DataTableRowGroupHeaderTemplateOptions { +interface DataTableRowGroupFooterTemplateOptions extends DataTableRowGroupHeaderTemplateOptions { colSpan: number; } @@ -130,9 +130,9 @@ interface DataTableDataSelectableParams { index: number; } -interface DataTableSelectionChangeParams { +interface DataTableSelectionChangeParams { originalEvent: React.SyntheticEvent; - value: any; + value: DataTableSelection; type?: string; [key: string]: any; } @@ -158,7 +158,7 @@ interface DataTableCellClickEventParams { originalEvent: React.MouseEvent; value: any; field: string; - rowData: any; + rowData: DataTableValue; rowIndex: number; cellIndex: number; selected: boolean; @@ -173,7 +173,7 @@ interface DataTableRowEditSaveParams extends DataTableRowEditParams { } interface DataTableRowEditCompleteParams extends DataTableRowEventParams { - newData: any; + newData: DataTableValue; field: string; index: number; } @@ -187,9 +187,9 @@ interface DataTableSelectParams { interface DataTableUnselectParams extends DataTableSelectParams {} interface DataTableExportFunctionParams { - data: any; + data: DataTableValueArray; field: string; - rowData: any; + rowData: DataTableValue; column: Column; } @@ -212,33 +212,58 @@ interface DataTableRowExpansionTemplate { customRendering: boolean; } -interface DataTableRowClassNameOptions { - props: DataTableProps; +interface DataTableRowClassNameOptions { + props: DataTableProps; } -interface DataTableCellClassNameOptions { - props: DataTableProps; - rowData: any; +interface DataTableCellClassNameOptions { + props: DataTableProps; column: Column; + field: string; + frozenRow: boolean; + rowIndex: number; } -interface DataTableShowSelectionElementOptions { +interface DataTableShowSelectionElementOptions { rowIndex: number; - props: DataTableProps; + props: DataTableProps; } -interface DataTableShowRowReorderElementOptions { +interface DataTableShowRowReorderElementOptions { rowIndex: number; - props: DataTableProps; + props: DataTableProps; } -interface DataTableRowEditValidatorOptions { - props: DataTableProps; +interface DataTableRowEditValidatorOptions { + props: DataTableProps; } -export interface DataTableProps extends Omit, HTMLDivElement>, 'size' | 'onContextMenu' | 'ref'> { +interface DataTableValue extends Record {} + +interface DataTableValueArray extends Array {} + +type DataTableRowData = { + [K in keyof TValue]: TValue[K]; +}; + +type DataTableRowDataArray = DataTableRowData[]; + +type DataTableCellSelection = { + cellIndex: number; + column: Column; + field: string; + props: ColumnProps; + rowData: DataTableRowData; + rowIndex: number; + selected: boolean; + value: TValue[keyof TValue]; +}; + +type DataTableSelection = DataTableRowData | DataTableRowDataArray | DataTableCellSelection; + +export interface DataTableProps extends Omit, HTMLDivElement>, 'size' | 'onContextMenu' | 'ref' | 'value'> { id?: string; - value?: any[]; + value?: TValue; alwaysShowPaginator?: boolean; autoLayout?: boolean; breakpoint?: string; @@ -254,26 +279,26 @@ export interface DataTableProps extends Omit; footerColumnGroup?: React.ReactNode; - frozenValue?: any[]; + frozenValue?: DataTableRowData[]; frozenWidth?: string; globalFilter?: DataTableGlobalFilterType; globalFilterFields?: string[]; globalFilterMatchMode?: ColumnFilterMatchModeType; groupRowsBy?: string; - header?: DataTableHeaderTemplateType; + header?: DataTableHeaderTemplateType; headerColumnGroup?: React.ReactNode; lazy?: boolean; loading?: boolean; @@ -293,8 +318,8 @@ export interface DataTableProps extends Omit; + rowGroupHeaderTemplate?: DataTableRowGroupHeaderTemplateType; rowGroupMode?: string; rowHover?: boolean; rows?: number; @@ -304,7 +329,7 @@ export interface DataTableProps extends Omit; selectionAutoFocus?: boolean; selectionAriaLabel?: string; selectionMode?: DataTableSelectionModeType; @@ -324,7 +349,7 @@ export interface DataTableProps extends Omit): object | string; customRestoreState?(): object; customSaveState?(state: object): void; exportFunction?(e: DataTableExportFunctionParams): any; @@ -339,7 +364,7 @@ export interface DataTableProps extends Omit): void; onFilter?(e: DataTablePFSEvent): void; onPage?(e: DataTablePFSEvent): void; onRowClick?(e: DataTableRowClickEventParams): void; @@ -358,20 +383,20 @@ export interface DataTableProps extends Omit): void; onSort?(e: DataTablePFSEvent): void; onStateRestore?(state: object): void; onStateSave?(state: object): void; onValueChange?(value: any[]): void; - rowClassName?(data: any, options: DataTableRowClassNameOptions): object | string; - rowEditValidator?(data: any, options: DataTableRowEditValidatorOptions): boolean; - rowExpansionTemplate?(data: any, options: DataTableRowExpansionTemplate): React.ReactNode; - showRowReorderElement?(data: any, options: DataTableShowRowReorderElementOptions): boolean | undefined | null; - showSelectionElement?(data: any, options: DataTableShowSelectionElementOptions): boolean | undefined | null; + rowClassName?(data: DataTableRowData, options: DataTableRowClassNameOptions): object | string; + rowEditValidator?(data: DataTableRowData, options: DataTableRowEditValidatorOptions): boolean; + rowExpansionTemplate?(data: DataTableRowData, options: DataTableRowExpansionTemplate): React.ReactNode; + showRowReorderElement?(data: DataTableRowData, options: DataTableShowRowReorderElementOptions): boolean | undefined | null; + showSelectionElement?(data: DataTableRowData, options: DataTableShowSelectionElementOptions): boolean | undefined | null; children?: React.ReactNode; } -export declare class DataTable extends React.Component { +export declare class DataTable extends React.Component, any> { public clearState(): void; public closeEditingCell(): void; public exportCSV(options?: { selectionOnly: boolean }): void;