UNPKG

@anglr/grid

Version:
64 lines 2.83 kB
import { Directive, Inject, Input } from '@angular/core'; import { GRID_INSTANCE, GridPluginType, NoMetadataSelectorComponent, NoPagingComponent, SyncDataLoaderComponent } from '@anglr/grid'; import { nameof } from '@jscrpt/common'; import { lastValueFrom } from '@jscrpt/common/rxjs'; import { first } from 'rxjs'; import * as i0 from "@angular/core"; /** * Directive that sets up static data for grid */ export class GridDataDirective { //######################### constructor ######################### constructor(_grid) { this._grid = _grid; this._grid.gridOptions = { plugins: { dataLoader: { type: SyncDataLoaderComponent, options: { data: [], }, }, paging: { type: NoPagingComponent, options: { initialItemsPerPage: 250, }, }, metadataSelector: { type: NoMetadataSelectorComponent, }, }, }; } //######################### public methods - implementation of OnChanges ######################### /** * Called when input value changes */ async ngOnChanges(changes) { if (nameof('data') in changes) { await lastValueFrom(this._grid.initialized.pipe(first(itm => itm))); const data = this.data ?? []; this._grid.execute(grid => { const dataLoader = grid.getPlugin(GridPluginType.DataLoader); dataLoader.options.data = Array.isArray(data) ? data : []; dataLoader.loadData(); }); } } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.1.0", ngImport: i0, type: GridDataDirective, deps: [{ token: GRID_INSTANCE }], target: i0.ɵɵFactoryTarget.Directive }); } static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.1.0", type: GridDataDirective, isStandalone: true, selector: "[ngGrid][data]", inputs: { data: "data" }, usesOnChanges: true, ngImport: i0 }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.1.0", ngImport: i0, type: GridDataDirective, decorators: [{ type: Directive, args: [{ selector: '[ngGrid][data]', }] }], ctorParameters: () => [{ type: undefined, decorators: [{ type: Inject, args: [GRID_INSTANCE] }] }], propDecorators: { data: [{ type: Input }] } }); //# sourceMappingURL=gridData.directive.js.map