1 import {Component, Input, OnInit, Host, TemplateRef} from '@angular/core';
2 import {GridColumn, GridColumnSet} from './grid';
3 import {GridComponent} from './grid.component';
6 selector: 'eg-grid-column',
7 template: '<ng-template></ng-template>'
10 export class GridColumnComponent implements OnInit {
12 // Note most input fields should match class fields for GridColumn
13 @Input() name: string;
14 @Input() path: string;
15 @Input() label: string;
16 @Input() flex: number;
17 // is this the index field?
18 @Input() index: boolean;
20 // Columns are assumed to be visible unless hidden=true.
21 @Input() hidden: boolean;
23 @Input() sortable: boolean;
24 @Input() datatype: string;
25 @Input() multiSortable: boolean;
27 // Display date and time when datatype = timestamp
28 @Input() datePlusTime: boolean;
30 // Used in conjunction with cellTemplate
31 @Input() cellContext: any;
32 @Input() cellTemplate: TemplateRef<any>;
34 // get a reference to our container grid.
35 constructor(@Host() private grid: GridComponent) {}
40 console.warn('GridColumnComponent needs an <eg-grid>');
44 const col = new GridColumn();
47 col.label = this.label;
49 col.hidden = this.hidden === true;
50 col.isIndex = this.index === true;
51 col.cellTemplate = this.cellTemplate;
52 col.cellContext = this.cellContext;
53 col.isSortable = this.sortable;
54 col.isMultiSortable = this.multiSortable;
55 col.datatype = this.datatype;
56 col.datePlusTime = this.datePlusTime;
58 this.grid.context.columnSet.add(col);