1 import {Component, Input, OnInit, Host, TemplateRef} from '@angular/core';
2 import {GridColumn} 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 // If true, boolean fields support 3 values: true, false, null (unset)
28 @Input() ternaryBool: boolean;
31 @Input() filterable: boolean;
33 // Display date and time when datatype = timestamp
34 @Input() datePlusTime: boolean;
36 // Display using a specific OU's timestamp when datatype = timestamp
37 @Input() timezoneContextOrg: number;
39 // Used in conjunction with cellTemplate
40 @Input() cellContext: any;
41 @Input() cellTemplate: TemplateRef<any>;
42 @Input() cellPrintValue: (row: any, cell: GridColumn) => string;
44 @Input() disableTooltip: boolean;
46 // get a reference to our container grid.
47 constructor(@Host() private grid: GridComponent) {}
52 console.warn('GridColumnComponent needs an <eg-grid>');
56 const col = new GridColumn();
59 col.label = this.label;
61 col.hidden = this.hidden === true;
62 col.isIndex = this.index === true;
63 col.cellTemplate = this.cellTemplate;
64 col.cellPrintValue = this.cellPrintValue;
65 col.cellContext = this.cellContext;
66 col.disableTooltip = this.disableTooltip;
67 col.isSortable = this.sortable;
68 col.isFilterable = this.filterable;
69 col.isMultiSortable = this.multiSortable;
70 col.datatype = this.datatype;
71 col.datePlusTime = this.datePlusTime;
72 col.ternaryBool = this.ternaryBool;
73 col.timezoneContextOrg = this.timezoneContextOrg;
75 this.grid.context.columnSet.add(col);