UNPKG

@ng-dominus/dm-table

Version:
112 lines (111 loc) 3.67 kB
import { BehaviorSubject, Observable } from "rxjs"; import { HttpClient, HttpContext, HttpHeaders, HttpParams } from "@angular/common/http"; import { MatSort } from "@angular/material/sort"; import { MatPaginator } from "@angular/material/paginator"; import { MatTableDataSource } from "@angular/material/table"; import { ngClassCompatible } from "../shared/types"; import { FormGroup } from "@angular/forms"; import { InjectionToken, ProviderToken, Type } from "@angular/core"; export interface DmTableColumnDefinition { /** * This will be matched against the data source when providing value for this column. * For example the column id 'my_column' should be found in the data source, like so: [{'my_column': 'column_value'}, ...]. */ id: string; /** * The column display name. */ name: string; /** * Classes to be placed on the whole column (th & td). * The values must be compatible with ngClass. */ classes?: ngClassCompatible; /** * Is this column sortable? */ sortable?: boolean; /** * Whether this column is displayed or hidden. */ visible?: boolean; /** * Render this column using a pipe or a component. * If both are set, the component property takes priority */ renderUsing?: { component?: Type<any>; pipe?: ProviderToken<any>; /** * arguments to be passed to either the pipe or the component */ arguments?: any[] | { [key: string]: any; }; }; } export interface DmTableRow { [columnId: string]: any; } export interface DmTableRenderComponentData { columnId: string; columnData: string; arguments: any[] | { [key: string]: any; }; } export declare enum DmTableIntl { NO_DATA = 0, LOADING = 1 } export declare const DM_TABLE_INTL: InjectionToken<Record<DmTableIntl, string>>; export declare const DM_TABLE_RENDER_COMPONENT_DATA: InjectionToken<DmTableRenderComponentData>; export type DmTableDataSource = string | { [columnId: string]: any; }[]; export type DmTableFilters = { [filter: string]: any; } | FormGroup; export interface DmTableDataServerResponse { totalResults: number; rows: DmTableRow[]; } export interface DmTableRequestOptions { body?: any; headers?: HttpHeaders | { [header: string]: string | string[]; }; context?: HttpContext; observe?: 'body'; params?: HttpParams | { [param: string]: string | number | boolean | ReadonlyArray<string | number | boolean>; }; responseType?: 'json'; } export interface DmTableColumnVisibility { columnId: string; /** * If not specified, the visibility will be toggled */ visible?: boolean; } export declare class DmTableDataSourceAdapter extends MatTableDataSource<any> { private requestMethod; private http; private dataSrc; private readonly onBeforeRequest; private mapRowsFn?; private filters?; private totalResults; private eventsSub; private loadingData$; private readonly paginatorRef?; private readonly sortRef?; constructor(requestMethod: string, http: HttpClient, dataSrc: DmTableDataSource, sort: MatSort, onBeforeRequest: (requestOptions: DmTableRequestOptions) => Promise<DmTableRequestOptions>, paginator?: MatPaginator, mapRowsFn?: ((rows: any[]) => any[]) | undefined, filters?: DmTableFilters | undefined); connect(): BehaviorSubject<any[]>; getTotalResults(): number; refresh(resetPage?: boolean): void; onDataLoading(): Observable<boolean>; private handleServerSideDataSrc; disconnect(): void; }