editor.component.ts
1.46 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
import { Component, ViewContainerRef, ViewChild, AfterViewInit } from '@angular/core';
import { AgEditorComponent } from 'ag-grid-ng2/main';
@Component({
selector: 'editor-cell',
template: `
<div class="md-select-panel">
<div #container class="md-select-content">
<md-option *ngFor="let item of data" (click)="onClick(item[this.params.valueCol])" >
{{item[this.params.labelCol]}}
</md-option>
</div>
</div>
`
})
export class EditorComponent implements AgEditorComponent, AfterViewInit {
@ViewChild('container', {read: ViewContainerRef}) public container;
public item: Object = null;
public data: Object[];
private params: any;
ngAfterViewInit() {
this.container.element.nativeElement.focus();
}
agInit(params: any): void {
this.params = params;
if (!this.params.valueCol) {
this.params.valueCol = 'id';
}
if (!this.params.labelCol) {
this.params.labelCol = 'name';
}
this.data = params.data || [];
}
getValue(): any {
return this.item;
}
isPopup(): boolean {
return true;
}
setValue(item: Object): void {
this.item = item;
}
onClick(item: Object) {
this.setValue(item);
this.params.api.stopEditing();
}
onKeyDown(event): boolean {
event.stopPropagation();
return false;
}
}