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 // Note most input fields should match class fields for GridColumn
13 @Input() label: string;
15 // Register to click events
16 @Output() onClick: EventEmitter<any []>;
18 // DEPRECATED: Pass a reference to a function that is called on click.
19 @Input() action: (rows: any[]) => any;
21 // When present, actions will be grouped by the provided label.
22 @Input() group: string;
24 // Optional: add a function that returns true or false.
25 // If true, this action will be disabled; if false
26 // (default behavior), the action will be enabled.
27 @Input() disableOnRows: (rows: any[]) => boolean;
30 // get a reference to our container grid.
31 constructor(@Host() private grid: GridComponent) {
32 this.onClick = new EventEmitter<any []>();
38 console.warn('GridToolbarActionComponent needs a [grid]');
42 const action = new GridToolbarAction();
43 action.label = this.label;
44 action.action = this.action;
45 action.onClick = this.onClick;
46 action.group = this.group;
47 action.disableOnRows = this.disableOnRows;
48 this.grid.context.toolbarActions.push(action);