@itwin/presentation-components
Version:
React components based on iTwin.js Presentation library
83 lines • 4.09 kB
TypeScript
/** @packageDocumentation
* @module Table
*/
import { IModelConnection } from "@itwin/core-frontend";
import { KeySet, Ruleset } from "@itwin/presentation-common";
import { SelectionStorage } from "@itwin/unified-selection";
import { TableColumnDefinition, TableRowDefinition } from "./Types.js";
/**
* Props for [[usePresentationTable]] hook.
* @public
*/
export interface UsePresentationTableProps<TColumn, TRow> {
/** iModel connection to pull data from. */
imodel: IModelConnection;
/** Ruleset or ruleset id that should be used to load data. */
ruleset: Ruleset | string;
/** Keys defining what to request data for. */
keys: Readonly<KeySet>;
/** Paging size for obtaining rows. */
pageSize: number;
/** Function that maps one column from generic [[TableColumnDefinition]] to table component specific type. */
columnMapper: (columns: TableColumnDefinition) => TColumn;
/** Function that maps one row from generic [[TableRowDefinition]] to table component specific type. */
rowMapper: (row: TableRowDefinition) => TRow;
}
/**
* Return type of [[usePresentationTable]] hook.
* @public
*/
export interface UsePresentationTableResult<TColumns, TRow> {
/** List of table columns. If columns are not loaded yet it is set to `undefined` */
columns: TColumns[] | undefined;
/** List of table rows loaded. */
rows: TRow[];
/** Specifies whether rows loading is on going. */
isLoading: boolean;
/** Loads more rows if there are any available. If there are no rows available it is no-op. */
loadMoreRows: () => void;
/** Sorts table data by the specific column. If called with `undefined` column name sorting is removed. */
sort: (columnName?: string, descending?: boolean) => void;
/** Filters table data using provided ECExpression. If called with `undefined` filtering is removed. */
filter: (filterExpression?: string) => void;
}
/**
* Custom hook that loads data for generic table component.
* @throws on failure to get table data. The error is thrown in the React's render loop, so it can be caught using an error boundary.
* @public
*/
export declare function usePresentationTable<TColumn, TRow>(props: UsePresentationTableProps<TColumn, TRow>): UsePresentationTableResult<TColumn, TRow>;
/**
* Props for [[usePresentationTableWithUnifiedSelection]] hook.
* @public
*/
export interface UsePresentationTableWithUnifiedSelectionProps<TColumn, TRow> extends Omit<UsePresentationTableProps<TColumn, TRow>, "keys"> {
/**
* Unified selection storage to use for listening, getting and changing active selection.
*
* When not specified, the deprecated `SelectionManager` from `@itwin/presentation-frontend` package
* is used.
*/
selectionStorage?: SelectionStorage;
}
/**
* Return type of [[usePresentationTableWithUnifiedSelection]] hook.
* @public
*/
export interface UsePresentationTableWithUnifiedSelectionResult<TColumns, TRow> extends UsePresentationTableResult<TColumns, TRow> {
/** Specifies rows that have been selected (toggled) by other components on the appropriate selection level. */
selectedRows: TRow[];
/**
* A function that should be called when a table row is selected.
* @param selectedRowKeys Keys of selected table rows. These should match `TableRowDefinition.key` passed to `UsePresentationTableProps.rowMapper` function when new rows are loaded.
*/
onSelect: (selectedRowKeys: string[]) => void;
}
/**
* Custom hook that load data for generic table component. It uses [Unified Selection]($docs/presentation/unified-selection/index.md) to get keys defining what to load rows for.
*
* @throws on failure to get table data. The error is thrown in the React's render loop, so it can be caught using an error boundary.
* @public
*/
export declare function usePresentationTableWithUnifiedSelection<TColumn, TRow>(props: UsePresentationTableWithUnifiedSelectionProps<TColumn, TRow>): UsePresentationTableWithUnifiedSelectionResult<TColumn, TRow>;
//# sourceMappingURL=UsePresentationTable.d.ts.map