UNPKG

@progress/kendo-angular-pivotgrid

Version:
93 lines (92 loc) 4.56 kB
/**----------------------------------------------------------------------------------------- * Copyright © 2025 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the project root for more information *-------------------------------------------------------------------------------------------*/ import { Directive, Input, NgZone } from '@angular/core'; import { PivotGridDataService } from './pivotgrid-data.service'; import { createDataTree, createFlatSchemaDimensions, createLocalDataState, rootFields } from '@progress/kendo-pivotgrid-common'; import { anyChanged } from '@progress/kendo-angular-common'; import { PivotBaseBindingDirective } from './base-binding-directive'; import * as i0 from "@angular/core"; import * as i1 from "./pivotgrid-data.service"; const dataField = 'aggregate'; const columnsData = 'columns'; const bindingFields = { dataField, columnsData }; const stringSeparator = '&'; /** * A directive which binds the PivotGrid to local data ([see example]({% slug directives_databinding_local_pivotgrid %})). */ export class PivotLocalBindingDirective extends PivotBaseBindingDirective { /** * The array of data which will be used to populate the PivotGrid. */ data; /** * Represents the dimensions object of the PivotGrid. */ dimensions; /** * Represents the measures collection of the PivotGrid. */ measures; type = 'local'; constructor(dataService, zone) { super(dataService, zone); } ngOnChanges(changes) { if (anyChanged(['data', 'dimensions', 'columnAxes', 'rowAxes', 'measureAxes', 'measures'], changes)) { this.loadData(this.dataService.state); } } /** * @hidden */ fetchChildren(node) { return node.children; } loadFields() { this.configuratorFields = createFlatSchemaDimensions(this.dimensions, this.measures); this.updateConfiguratorFields(); } loadData(state) { const { columnAxes, rowAxes, measureAxes, sort, filter } = state; const rootColumnAxes = this.getRootAxes(columnAxes); const rootRowAxes = this.getRootAxes(rowAxes); const columnSettings = rootColumnAxes ? rootColumnAxes.split(stringSeparator).map(this.createAxisSettings) : []; const rowSettings = rootRowAxes ? rootRowAxes.split(stringSeparator).map(this.createAxisSettings) : []; const measuresSettings = measureAxes.map(m => this.measures.find(meas => String(meas.name) === String(m.name))).filter(Boolean); const dataTree = createDataTree(this.data, rowSettings, columnSettings, measuresSettings, bindingFields, filter); this.dataState = createLocalDataState({ dataTree, rowSettings, columnSettings, rowAxes: rowAxes, columnAxes: columnAxes, measures: measuresSettings, sort: sort, fields: bindingFields }); this.updateDataServiceFields(); } createAxisSettings = (key) => ({ key, ...this.dimensions[key] }); getRootAxes(axes) { return Array.from(rootFields(axes).keys()).join(stringSeparator); } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: PivotLocalBindingDirective, deps: [{ token: i1.PivotGridDataService }, { token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Directive }); static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.12", type: PivotLocalBindingDirective, isStandalone: true, selector: "[kendoPivotLocalBinding]", inputs: { data: ["kendoPivotLocalBinding", "data"], dimensions: "dimensions", measures: "measures" }, exportAs: ["kendoPivotLocalBinding"], usesInheritance: true, usesOnChanges: true, ngImport: i0 }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: PivotLocalBindingDirective, decorators: [{ type: Directive, args: [{ selector: '[kendoPivotLocalBinding]', exportAs: 'kendoPivotLocalBinding', standalone: true }] }], ctorParameters: function () { return [{ type: i1.PivotGridDataService }, { type: i0.NgZone }]; }, propDecorators: { data: [{ type: Input, args: ['kendoPivotLocalBinding'] }], dimensions: [{ type: Input }], measures: [{ type: Input }] } });