1 import {Component, Input, Output, OnInit, Host, TemplateRef, EventEmitter} from '@angular/core';
2 import {GridToolbarAction} from './grid';
3 import {GridComponent} from './grid.component';
6 selector: 'eg-grid-toolbar-action',
7 template: '<ng-template></ng-template>'
10 export class GridToolbarActionComponent implements OnInit {
12 toolbarAction: GridToolbarAction;
14 // Note most input fields should match class fields for GridColumn
15 @Input() label: string;
17 // Register to click events
18 @Output() onClick: EventEmitter<any []>;
20 // When present, actions will be grouped by the provided label.
21 @Input() group: string;
23 // DEPRECATED: Pass a reference to a function that is called on click.
24 @Input() action: (rows: any[]) => any;
26 @Input() set disabled(d: boolean) {
27 this.toolbarAction.disabled = d;
29 get disabled(): boolean {
30 return this.toolbarAction.disabled;
33 // Optional: add a function that returns true or false.
34 // If true, this action will be disabled; if false
35 // (default behavior), the action will be enabled.
36 @Input() disableOnRows: (rows: any[]) => boolean;
39 // get a reference to our container grid.
40 constructor(@Host() private grid: GridComponent) {
41 this.onClick = new EventEmitter<any []>();
42 this.toolbarAction = new GridToolbarAction();
48 console.warn('GridToolbarActionComponent needs a [grid]');
53 console.debug('toolbar [action] is deprecated. use (onClick) instead.');
56 this.toolbarAction.label = this.label;
57 this.toolbarAction.onClick = this.onClick;
58 this.toolbarAction.group = this.group;
59 this.toolbarAction.action = this.action;
60 this.toolbarAction.disabled = this.disabled;
61 this.toolbarAction.disableOnRows = this.disableOnRows;
62 this.grid.context.toolbarActions.push(this.toolbarAction);