This repository was archived by the owner on Dec 25, 2021. It is now read-only.
forked from MIt9/angular-4-data-table
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathrow.component.ts
More file actions
89 lines (74 loc) · 2 KB
/
row.component.ts
File metadata and controls
89 lines (74 loc) · 2 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import {
Component,
ElementRef,
EventEmitter,
forwardRef,
Inject,
Input,
OnDestroy,
OnInit,
Output,
Renderer2
} from '@angular/core';
import { DataTableComponent } from '../table/table.component';
@Component({
selector: '[dataTableRow]',
templateUrl: './row.component.html',
styleUrls: ['./row.component.css']
})
export class DataTableRowComponent implements OnInit, OnDestroy {
public _this = this;
@Input() item: any;
@Input() index: number;
expanded: boolean;
private _listeners = [];
// row selection:
private _selected: boolean;
@Output() selectedChange = new EventEmitter();
@Output() rowExpandEvent = new EventEmitter();
get selected() {
return this._selected;
}
set selected(selected) {
this._selected = selected;
this.selectedChange.emit(selected);
}
expandButtonClicked(){
this.expanded = !this.expanded;
this.rowExpandEvent.emit(this.expanded);
}
// other:
get displayIndex() {
if (this.dataTable.pagination) {
return this.dataTable.displayParams.offset + this.index + 1;
} else {
return this.index + 1;
}
}
getTooltip() {
if (this.dataTable.rowTooltip) {
return this.dataTable.rowTooltip(this.item, this, this.index);
}
return '';
}
constructor(@Inject(forwardRef(() => DataTableComponent)) public dataTable: DataTableComponent,
private renderer: Renderer2, private elementRef: ElementRef) {}
ngOnInit() {
if (this.dataTable.rowClick.observers.length > 0) {
this._listeners.push(
this.renderer.listen(this.elementRef.nativeElement, 'click',
(event) => this.dataTable.rowClicked(this, event))
);
}
if (this.dataTable.rowDoubleClick.observers.length > 0) {
this._listeners.push(
this.renderer.listen(this.elementRef.nativeElement, 'dblclick',
(event) => this.dataTable.rowDoubleClicked(this, event))
);
}
}
ngOnDestroy() {
this.selected = false;
this._listeners.forEach(fn => fn());
}
}