]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/eg2/src/app/share/grid/grid-column.component.ts
76a89f61bf0c5c92223d79a67934be60c35e2aa1
[Evergreen.git] / Open-ILS / src / eg2 / src / app / share / grid / grid-column.component.ts
1 import {Component, Input, OnInit, Host, TemplateRef} from '@angular/core';
2 import {GridColumn, GridColumnSet} from './grid';
3 import {GridComponent} from './grid.component';
4
5 @Component({
6   selector: 'eg-grid-column',
7   template: '<ng-template></ng-template>'
8 })
9
10 export class GridColumnComponent implements OnInit {
11
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;
19
20     // Columns are assumed to be visible unless hidden=true.
21     @Input() hidden: boolean;
22
23     @Input() sortable: boolean;
24     @Input() datatype: string;
25     @Input() multiSortable: boolean;
26
27     // Display date and time when datatype = timestamp
28     @Input() datePlusTime: boolean;
29
30     // Used in conjunction with cellTemplate
31     @Input() cellContext: any;
32     @Input() cellTemplate: TemplateRef<any>;
33
34     @Input() disableTooltip: boolean;
35
36     // get a reference to our container grid.
37     constructor(@Host() private grid: GridComponent) {}
38
39     ngOnInit() {
40
41         if (!this.grid) {
42             console.warn('GridColumnComponent needs an <eg-grid>');
43             return;
44         }
45
46         const col = new GridColumn();
47         col.name = this.name;
48         col.path = this.path;
49         col.label = this.label;
50         col.flex = this.flex;
51         col.hidden = this.hidden === true;
52         col.isIndex = this.index === true;
53         col.cellTemplate = this.cellTemplate;
54         col.cellContext = this.cellContext;
55         col.disableTooltip = this.disableTooltip;
56         col.isSortable = this.sortable;
57         col.isMultiSortable = this.multiSortable;
58         col.datatype = this.datatype;
59         col.datePlusTime = this.datePlusTime;
60         col.isAuto = false;
61         this.grid.context.columnSet.add(col);
62     }
63 }
64