1 import {Component, Input, OnInit, Host, TemplateRef} 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;
14 @Input() action: (rows: any[]) => any;
16 // Optional: add a function that returns true or false.
17 // If true, this action will be disabled; if false
18 // (default behavior), the action will be enabled.
19 @Input() disableOnRows: (rows: any[]) => boolean;
21 // get a reference to our container grid.
22 constructor(@Host() private grid: GridComponent) {}
27 console.warn('GridToolbarActionComponent needs a [grid]');
31 const action = new GridToolbarAction();
32 action.label = this.label;
33 action.action = this.action;
35 action.disableOnRows = (this.disableOnRows === null) ?
36 (rows: any[]) => false : this.disableOnRows;
38 this.grid.context.toolbarActions.push(action);