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 // These are optional labels that can come before and after the button
16 @Input() adjacentPreceedingLabel = '';
17 @Input() adjacentSubsequentLabel = '';
19 // Register to click events
20 @Output() onClick: EventEmitter<any>;
22 // DEPRECATED: Pass a reference to a function that is called on click.
23 @Input() action: () => any;
25 // Provide a router link instead of an onClick handler
26 @Input() routerLink: string;
28 @Input() set disabled(d: boolean) {
29 // Support asynchronous disabled values by appling directly
30 // to our button object as values arrive.
32 this.button.disabled = d;
36 button: GridToolbarButton;
38 // get a reference to our container grid.
39 constructor(@Host() private grid: GridComponent) {
40 this.onClick = new EventEmitter<any>();
41 this.button = new GridToolbarButton();
46 console.warn('GridToolbarButtonComponent needs a [grid]');
50 this.button.onClick = this.onClick;
51 this.button.routerLink = this.routerLink;
52 this.button.label = this.label;
53 this.button.adjacentPreceedingLabel = this.adjacentPreceedingLabel;
54 this.button.adjacentSubsequentLabel = this.adjacentSubsequentLabel;
55 this.button.action = this.action;
56 this.grid.context.toolbarButtons.push(this.button);