UNPKG

@progress/kendo-angular-grid

Version:

Kendo UI Grid for Angular - high performance data grid with paging, filtering, virtualization, CRUD, and more.

90 lines (89 loc) 4.11 kB
/**----------------------------------------------------------------------------------------- * Copyright © 2025 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the project root for more information *-------------------------------------------------------------------------------------------*/ import { ChangeDetectorRef, Directive, Input } from '@angular/core'; import { Keys } from '@progress/kendo-angular-common'; import { EditingDirectiveBase } from './editing-directive-base'; import { GridComponent } from '../grid.component'; import { LocalDataChangesService } from '../editing/local-data-changes.service'; import { markAllAsTouched } from './utils'; import * as i0 from "@angular/core"; import * as i1 from "../grid.component"; import * as i2 from "../editing/local-data-changes.service"; /** * A directive which encapsulates the editing operations of the Grid when using the in-cell * editing with Reactive Forms ([see example]({% slug editing_directives_grid %}#toc-in-cell-editing)). */ export class InCellEditingDirective extends EditingDirectiveBase { grid; localDataChangesService; cdr; /** * The function that creates the `FormGroup` for the edited model. */ createFormGroup; constructor(grid, localDataChangesService, cdr) { super(grid, localDataChangesService); this.grid = grid; this.localDataChangesService = localDataChangesService; this.cdr = cdr; } // Need mixin createModel(args) { return this.createFormGroup(args); } saveModel({ dataItem, formGroup, isNew }) { if (!formGroup.dirty && !isNew) { return; } if (formGroup.valid) { this.editService.assignValues(dataItem, formGroup.value); return dataItem; } markAllAsTouched(formGroup); } /** * @hidden */ ngOnInit() { super.ngOnInit(); this.subscriptions.add(this.grid.cellClick.subscribe(this.cellClickHandler.bind(this))); this.subscriptions.add(this.grid.cellClose.subscribe(this.cellCloseHandler.bind(this))); } removeHandler(args) { super.removeHandler(args); this.grid.cancelCell(); } cellClickHandler(args) { if (!args.isEdited && args.type !== 'contextmenu') { this.grid.editCell(args.rowIndex, args.columnIndex, this.createFormGroup(args)); this.cdr.markForCheck(); } } cellCloseHandler(args) { const { formGroup, dataItem } = args; if (!formGroup.valid) { args.preventDefault(); } else if (formGroup.dirty) { if (args.originalEvent && args.originalEvent.keyCode === Keys.Escape) { return; } this.editService.assignValues(dataItem, formGroup.value); this.editService.update(dataItem); } } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: InCellEditingDirective, deps: [{ token: i1.GridComponent }, { token: i2.LocalDataChangesService }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Directive }); static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.12", type: InCellEditingDirective, isStandalone: true, selector: "[kendoGridInCellEditing]", inputs: { createFormGroup: ["kendoGridInCellEditing", "createFormGroup"] }, usesInheritance: true, ngImport: i0 }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: InCellEditingDirective, decorators: [{ type: Directive, args: [{ selector: '[kendoGridInCellEditing]', standalone: true }] }], ctorParameters: function () { return [{ type: i1.GridComponent }, { type: i2.LocalDataChangesService }, { type: i0.ChangeDetectorRef }]; }, propDecorators: { createFormGroup: [{ type: Input, args: ['kendoGridInCellEditing'] }] } });