UNPKG

@progress/kendo-angular-grid

Version:

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

65 lines (64 loc) 2.06 kB
/**----------------------------------------------------------------------------------------- * Copyright © 2025 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the project root for more information *-------------------------------------------------------------------------------------------*/ import { isDevMode } from '@angular/core'; import { GridConfigurationErrorMessages } from '../common/error-messages'; /** * @hidden */ export class LocalEditService { grid; localDataChangesService; constructor(grid, localDataChangesService) { this.grid = grid; this.localDataChangesService = localDataChangesService; } create(item) { if (this.hasLocalData && this.grid.skip) { this.localDataChangesService.data.splice(this.grid.skip, 0, item); } else { this.data.unshift(item); } this.dataChanged(); } // eslint-disable-next-line @typescript-eslint/no-empty-function update(_item) { /* noop */ } remove(item) { const data = this.data; for (let idx = 0; idx < data.length; idx++) { if (item === data[idx]) { data.splice(idx, 1); this.dataChanged({ action: 'remove', item: item }); break; } } } assignValues(target, source) { Object.assign(target, source); } dataChanged(args = {}) { if (this.hasLocalData) { this.localDataChangesService.changes.emit(args); } } get hasLocalData() { return Array.isArray(this.localDataChangesService.data); } get data() { if (this.hasLocalData) { return this.localDataChangesService.data; } const data = this.grid.data; if (Array.isArray(data)) { return data; } if (isDevMode()) { throw new Error(GridConfigurationErrorMessages.requiredEditService); } return []; } }