1 import {Component, Input, Output, OnInit, Host, TemplateRef, EventEmitter} from '@angular/core';
2 import {GridToolbarButton} from './grid';
3 import {GridComponent} from './grid.component';
6 selector: 'eg-grid-toolbar-button',
7 template: '<ng-template></ng-template>'
10 export class GridToolbarButtonComponent 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: () => any;
22 @Input() set disabled(d: boolean) {
23 // Support asynchronous disabled values by appling directly
24 // to our button object as values arrive.
26 this.button.disabled = d;
30 button: GridToolbarButton;
32 // get a reference to our container grid.
33 constructor(@Host() private grid: GridComponent) {
34 this.onClick = new EventEmitter<any>();
35 this.button = new GridToolbarButton();
36 this.button.onClick = this.onClick;
42 console.warn('GridToolbarButtonComponent needs a [grid]');
46 this.button.label = this.label;
47 this.button.action = this.action;
48 this.grid.context.toolbarButtons.push(this.button);