UNPKG

@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.

49 lines (48 loc) 1.83 kB
/**----------------------------------------------------------------------------------------- * Copyright © 2025 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the project root for more information *-------------------------------------------------------------------------------------------*/ import { LocalEditService } from './local-edit.service'; import { insertNewItem } from './utils'; /** * @hidden */ export class HierarchyEditService extends LocalEditService { bindingDirective; constructor(bindingDirective) { super(); this.bindingDirective = bindingDirective; } create(item, parent, _id) { const { childrenGetter, childrenSetter, originalData, component } = this.bindingDirective; if (parent) { const children = childrenGetter(parent); if (children) { children.unshift(item); } else { childrenSetter(parent, [item]); } } else { insertNewItem(item, originalData, component); } this.bindingDirective.rebind(); } update(_item) { this.bindingDirective.rebind(); } remove(item, parent) { const idGetter = this.bindingDirective.component.idGetter; // refactor provide idGetter via context service const { childrenGetter, originalData } = this.bindingDirective; const children = parent ? childrenGetter(parent) : originalData; if (children && children.length) { const id = idGetter(item); const index = children.findIndex(i => idGetter(i) === id); if (index >= 0) { children.splice(index, 1); this.bindingDirective.rebind(); } } } }