UNPKG

@progress/kendo-angular-grid

Version:

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

115 lines (114 loc) 5.71 kB
/**----------------------------------------------------------------------------------------- * Copyright © 2025 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the project root for more information *-------------------------------------------------------------------------------------------*/ import { Component, HostListener, HostBinding, Inject, ElementRef, Renderer2 as Renderer, NgZone } from '@angular/core'; import { Button } from '@progress/kendo-angular-buttons'; import { EditService } from './edit.service'; import { CELL_CONTEXT } from '../rendering/common/cell-context'; import { ContextService } from '../common/provider.service'; import { NgIf, NgClass } from '@angular/common'; import { IconWrapperComponent } from '@progress/kendo-angular-icons'; import * as i0 from "@angular/core"; import * as i1 from "./edit.service"; import * as i2 from "../common/provider.service"; /** * Represents the `edit` command of the Grid. You can apply this directive to any `button` * element inside a [CommandColumnComponent]({% slug api_grid_commandcolumncomponent %}). * When an associated button with the directive is clicked, the * [edit]({% slug api_grid_gridcomponent %}#toc-edit) event * is triggered ([see example]({% slug basics_editing_grid %})). * * When the row is in the `edit` mode, the button with `kendoGridEditCommand` is automatically hidden. * * @example * ```html * <kendo-grid> * <kendo-grid-command-column title="command"> * <ng-template kendoGridCellTemplate> * <button kendoGridEditCommand class="k-primary">Edit</button> * </ng-template> * </kendo-grid-command-column> * </kendo-grid> * ``` * */ export class EditCommandDirective extends Button { editService; cellContext; rowIndex; isEdited; /** * @hidden */ get visible() { return this.isEdited ? 'none' : ''; } /** * @hidden */ commandClass = true; /** * @hidden */ onClick(e) { e.preventDefault(); this.editService.beginEdit(this.rowIndex); } constructor(editService, cellContext, element, renderer, ctx, ngZone) { super(element, renderer, null, ctx.localization, ngZone); this.editService = editService; this.cellContext = cellContext; } ngDoCheck() { if (this.cellContext) { this.rowIndex = this.cellContext.rowIndex; this.isEdited = this.editService.isEdited(this.rowIndex); } } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: EditCommandDirective, deps: [{ token: i1.EditService }, { token: CELL_CONTEXT }, { token: i0.ElementRef }, { token: i0.Renderer2 }, { token: i2.ContextService }, { token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Component }); static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.2.12", type: EditCommandDirective, isStandalone: true, selector: "[kendoGridEditCommand]", host: { listeners: { "click": "onClick($event)" }, properties: { "style.display": "this.visible", "class.k-grid-edit-command": "this.commandClass" } }, usesInheritance: true, ngImport: i0, template: ` <kendo-icon-wrapper *ngIf="icon || svgIcon" innerCssClass="k-button-icon" [name]="icon" [svgIcon]="svgIcon"></kendo-icon-wrapper> <span *ngIf="imageUrl" class="k-button-icon k-icon"> <img [src]="imageUrl" class="k-image" role="presentation" /> </span> <span *ngIf="iconClass" class="k-button-icon" [ngClass]="iconClass"></span> <span class="k-button-text"><ng-content></ng-content></span> `, isInline: true, dependencies: [{ kind: "directive", type: NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: IconWrapperComponent, selector: "kendo-icon-wrapper", inputs: ["name", "svgIcon", "innerCssClass", "customFontClass", "size"], exportAs: ["kendoIconWrapper"] }, { kind: "directive", type: NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }] }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: EditCommandDirective, decorators: [{ type: Component, args: [{ selector: '[kendoGridEditCommand]', template: ` <kendo-icon-wrapper *ngIf="icon || svgIcon" innerCssClass="k-button-icon" [name]="icon" [svgIcon]="svgIcon"></kendo-icon-wrapper> <span *ngIf="imageUrl" class="k-button-icon k-icon"> <img [src]="imageUrl" class="k-image" role="presentation" /> </span> <span *ngIf="iconClass" class="k-button-icon" [ngClass]="iconClass"></span> <span class="k-button-text"><ng-content></ng-content></span> `, standalone: true, imports: [NgIf, IconWrapperComponent, NgClass] }] }], ctorParameters: function () { return [{ type: i1.EditService }, { type: undefined, decorators: [{ type: Inject, args: [CELL_CONTEXT] }] }, { type: i0.ElementRef }, { type: i0.Renderer2 }, { type: i2.ContextService }, { type: i0.NgZone }]; }, propDecorators: { visible: [{ type: HostBinding, args: ['style.display'] }], commandClass: [{ type: HostBinding, args: ['class.k-grid-edit-command'] }], onClick: [{ type: HostListener, args: ['click', ['$event']] }] } });