-
Notifications
You must be signed in to change notification settings - Fork 136
/
Copy pathcolumn.component.ts
53 lines (43 loc) · 1.44 KB
/
column.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { Directive, Input, ContentChild, OnInit } from '@angular/core';
import { DataTableRow } from './row.component';
import { CellCallback } from '../types/cell-callback.type';
@Directive({
selector: 'data-table-column'
})
export class DataTableColumn implements OnInit {
// init:
@Input() header: string;
@Input() sortable = false;
@Input() resizable = false;
@Input() property: string;
@Input() styleClass: string;
@Input() cellColors: CellCallback;
// init and state:
@Input() width: number | string;
@Input() visible = true;
@ContentChild('dataTableCell') cellTemplate;
@ContentChild('dataTableHeader') headerTemplate;
getCellColor(row: DataTableRow, index: number) {
if (this.cellColors !== undefined) {
return (<CellCallback>this.cellColors)(row.item, row, this, index);
}
}
private styleClassObject = {}; // for [ngClass]
ngOnInit() {
this._initCellClass();
}
private _initCellClass() {
if (!this.styleClass && this.property) {
if (/^[a-zA-Z0-9_]+$/.test(this.property)) {
this.styleClass = 'column-' + this.property;
} else {
this.styleClass = 'column-' + this.property.replace(/[^a-zA-Z0-9_]/g, '');
}
}
if (this.styleClass != null) {
this.styleClassObject = {
[this.styleClass]: true
};
}
}
}