@progress/kendo-angular-treelist
Version:
Kendo UI TreeList for Angular - Display hierarchical data in an Angular tree grid view that supports sorting, filtering, paging, and much more.
90 lines (89 loc) • 3.92 kB
JavaScript
/**-----------------------------------------------------------------------------------------
* 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 } from '@angular/core';
import { EditingDirectiveBase } from './editing-directive-base';
import { TreeListComponent } from '../treelist.component';
import { markAllAsTouched } from './utils';
import * as i0 from "@angular/core";
import * as i1 from "../treelist.component";
/**
* A directive that encapsulates the editing operations of the TreeList when using the in-cell
* editing with Reactive Forms. [See example](slug:editing_directives_treelist#toc-in-cell-editing-directive).
*
* @example
* ```html
* <kendo-treelist [kendoTreeListInCellEditing]="createFormGroup">
* <kendo-treelist-column field="name" title="Name"></kendo-treelist-column>
* <kendo-treelist-column field="age" title="Age"></kendo-treelist-column>
* </kendo-treelist>
* ```
* @remarks
* Applied to: {@link TreeListComponent}.
*/
export class InCellEditingDirective extends EditingDirectiveBase {
treelist;
/**
* The function that creates the `FormGroup` for the edited model.
*/
createFormGroup;
constructor(treelist) {
super(treelist);
this.treelist = treelist;
}
// 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.treelist.cellClick.subscribe(this.cellClickHandler.bind(this)));
this.subscriptions.add(this.treelist.cellClose.subscribe(this.cellCloseHandler.bind(this)));
}
removeHandler(args) {
super.removeHandler(args);
this.treelist.cancelCell();
}
cellClickHandler(args) {
if (!args.isEdited && args.type === 'click') {
this.treelist.editCell(args.dataItem, args.columnIndex, this.createFormGroup(args));
}
}
cellCloseHandler(args) {
const { formGroup, dataItem } = args;
if (!formGroup.valid) {
args.preventDefault();
}
else if (formGroup.dirty) {
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.TreeListComponent }], target: i0.ɵɵFactoryTarget.Directive });
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.12", type: InCellEditingDirective, isStandalone: true, selector: "[kendoTreeListInCellEditing]", inputs: { createFormGroup: ["kendoTreeListInCellEditing", "createFormGroup"] }, exportAs: ["kendoTreeListInCellEditing"], usesInheritance: true, ngImport: i0 });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: InCellEditingDirective, decorators: [{
type: Directive,
args: [{
exportAs: 'kendoTreeListInCellEditing',
selector: '[kendoTreeListInCellEditing]',
standalone: true
}]
}], ctorParameters: function () { return [{ type: i1.TreeListComponent }]; }, propDecorators: { createFormGroup: [{
type: Input,
args: ['kendoTreeListInCellEditing']
}] } });