1 import {Component, Input, OnInit, Host, Output, EventEmitter} from '@angular/core';
2 import {GridToolbarCheckbox} from './grid';
3 import {GridComponent} from './grid.component';
6 selector: 'eg-grid-toolbar-checkbox',
7 template: '<ng-template></ng-template>'
10 export class GridToolbarCheckboxComponent implements OnInit {
12 // Note most input fields should match class fields for GridColumn
13 @Input() label: string;
15 // Set the render time value.
16 // This does NOT fire the onChange handler.
17 @Input() initialValue: boolean;
19 @Output() onChange: EventEmitter<boolean>;
21 private cb: GridToolbarCheckbox;
23 // get a reference to our container grid.
24 constructor(@Host() private grid: GridComponent) {
25 this.onChange = new EventEmitter<boolean>();
27 // Create in constructor so we can accept values before the
28 // grid is fully rendered.
29 this.cb = new GridToolbarCheckbox();
30 this.cb.isChecked = null;
31 this.initialValue = null;
36 console.warn('GridToolbarCheckboxComponent needs a [grid]');
40 this.cb.label = this.label;
41 this.cb.onChange = this.onChange;
43 if (this.cb.isChecked === null && this.initialValue !== null) {
44 this.cb.isChecked = this.initialValue;
47 this.grid.context.toolbarCheckboxes.push(this.cb);
50 // Toggle the value. onChange is not fired.
52 this.cb.isChecked = !this.cb.isChecked;
55 // Set/get the value. onChange is not fired.
56 checked(value?: boolean): boolean {
57 if (value === true || value === false) {
58 this.cb.isChecked = value;
60 return this.cb.isChecked;