UNPKG

@sparser/au2-data-grid

Version:
144 lines 5.42 kB
import { IContainer } from '@aurelia/kernel'; import { CustomElementDefinition, ViewFactory } from '@aurelia/runtime-html'; import { SortDirection, SortOption } from './sorting-options.js'; export interface ExportableGridState { columns: ExportableColumnState[]; } export interface IGridState { export(): ExportableGridState; } export interface IGridStateModel extends GridStateModel { } export declare const IGridStateModel: import("@aurelia/kernel").InterfaceSymbol<IGridStateModel>; /** * This aggregates the structural metadata for the grid. * This is meant for internal use. * @internal */ export declare class GridStateModel implements IGridState { private _activeSortOptions; /** * @internal */ private subscribers; /** @internal */ private viewFactoriesCreated; readonly columns: Column[]; get activeSortOptions(): SortOption<Record<string, unknown>> | null; /** * Exports the grid state. */ export(): ExportableGridState; /** * Applies a previously exported state. * @param {ExportableGridState} state The state to apply. */ applyState(state: ExportableGridState): void; /** * Marks the hidden columns as per the given column ids. * Note that in absence of a `id` attribute in `grid-column`, the `property` is used as the `id`. * @param {string[]} columnIds The collection of ids of the columns to hide. */ hideColumns(columnIds: string[]): void; /** * Creates the view factories for every column using the given `container`. */ createViewFactories(container: IContainer): void; /** * Initializes the sort options. * To this end the first column with non-null direction is used . */ initializeActiveSortOptions(): SortOption<Record<string, unknown>> | null; /** * Adds the given `subscriber` to the collection of subscribers. * The subscribers will be notified for state changes. */ addSubscriber(subscriber: GridStateChangeSubscriber): void; /** * Removes the given `subscriber` from the collection of subscribers. * The subscriber won't be notified for any further state changes. */ removeSubscriber(subscriber: GridStateChangeSubscriber): void; private notifySubscribers; /** @internal */ handleChange(type: ChangeType.Width): void; handleChange(type: ChangeType.Sort, column: Column): void; handleChange(type: ChangeType.Order, sourceId: string, destination: Column, location: OrderChangeDropLocation): void; } export interface ExportableColumnState { readonly id: string; readonly property: string | null; readonly isResizable: boolean; widthPx: string | null; direction: SortDirection | null; } export interface ColumnState extends ExportableColumnState { setDirection(direction: SortDirection | null, notifyParent: boolean): void; export(): ExportableColumnState; } /** * This describes the structural metadata of a column. * This is meant for internal use. * @internal */ export declare class Column implements ColumnState { readonly parent: GridStateModel; readonly id: string; readonly property: string | null; private readonly exportable; readonly isResizable: boolean; widthPx: string | null; private readonly header; private readonly content; private static id; static generateId(): string; /** @internal */ private readonly _sortable; /** @internal */ private _direction; /** @internal */ private _headerViewFactory; /** @internal */ private _contentViewFactory; /** * This is registered from inside the grid-header CE during `binding`. * @internal */ headerElement?: HTMLElement; hidden: boolean; constructor(parent: GridStateModel, id: string, property: string | null, exportable: boolean, direction: SortDirection | null, isResizable: boolean, widthPx: string | null, header: CustomElementDefinition, content: CustomElementDefinition); get direction(): SortDirection | null; get sortable(): boolean; get headerViewFactory(): ViewFactory | null; get contentViewFactory(): ViewFactory | null; /** @internal */ setDirection(direction: SortDirection | null, notifyParent: boolean): void; export(): ExportableColumnState; /** @internal */ tryApplyState(state: ExportableColumnState): boolean; createViewFactories(container: IContainer): void; } export declare const enum ChangeType { /** Content sorting is changed. */ Sort = 1, /** Column is reordered. */ Order = 2, /** Width of a column is changed. */ Width = 3 } export declare const enum OrderChangeDropLocation { Before = 1, After = 2 } export interface OrderChangeData { fromIndex: number; toIndex: number; location: OrderChangeDropLocation; } export type GridStateChangeSubscriber = { handleGridStateChange(type: ChangeType.Width): void; handleGridStateChange(type: ChangeType.Order, value: OrderChangeData): void; handleGridStateChange(type: ChangeType.Sort, newValue: SortOption<Record<string, unknown>>, oldValue: SortOption<Record<string, unknown>> | null): void; handleGridStateChange(type: ChangeType, newValue?: SortOption<Record<string, unknown>> | OrderChangeData, oldValue?: SortOption<Record<string, unknown>> | null): void; }; //# sourceMappingURL=grid-state.d.ts.map