Commit 18ac329fcc638a817d26f2fd36168e24b7e336d7
1 parent
abf7c25f
Editors
Showing
3 changed files
with
25 additions
and
15 deletions
Show diff stats
src/app/components/editor.component.ts
... | ... | @@ -2,20 +2,18 @@ import { Component, ViewContainerRef, ViewChild, AfterViewInit } from '@angular/ |
2 | 2 | |
3 | 3 | import { AgEditorComponent } from 'ag-grid-ng2/main'; |
4 | 4 | |
5 | -import { RegionSelectList } from '../models/regionselectlist'; | |
6 | - | |
7 | 5 | @Component({ |
8 | 6 | selector: 'editor-cell', |
9 | 7 | template: ` |
10 | 8 | <div #container> |
11 | - <p *ngFor="let item of data" (click)="onClick(item)" >{{item.name}}</p> | |
9 | + <p *ngFor="let item of data" (click)="onClick(item)" >{{item[this.params.labelCol]}}</p> | |
12 | 10 | </div> |
13 | 11 | ` |
14 | 12 | }) |
15 | 13 | export class EditorComponent implements AgEditorComponent, AfterViewInit { |
16 | 14 | @ViewChild('container', {read: ViewContainerRef}) public container; |
17 | - public item: any; | |
18 | - public data: RegionSelectList[]; | |
15 | + public item: Object = null; | |
16 | + public data: Object[]; | |
19 | 17 | private params: any; |
20 | 18 | ngAfterViewInit() { |
21 | 19 | this.container.element.nativeElement.focus(); |
... | ... | @@ -23,8 +21,13 @@ export class EditorComponent implements AgEditorComponent, AfterViewInit { |
23 | 21 | |
24 | 22 | agInit(params: any): void { |
25 | 23 | this.params = params; |
24 | + if (!this.params.valueCol) { | |
25 | + this.params.valueCol = 'id'; | |
26 | + } | |
27 | + if (!this.params.labelCol) { | |
28 | + this.params.labelCol = 'name'; | |
29 | + } | |
26 | 30 | this.data = params.data || []; |
27 | - // this.setHappy(params.value === "Happy"); | |
28 | 31 | } |
29 | 32 | |
30 | 33 | getValue(): any { |
... | ... | @@ -35,11 +38,11 @@ export class EditorComponent implements AgEditorComponent, AfterViewInit { |
35 | 38 | return true; |
36 | 39 | } |
37 | 40 | |
38 | - setValue(item: any): void { | |
41 | + setValue(item: Object): void { | |
39 | 42 | this.item = item; |
40 | 43 | } |
41 | 44 | |
42 | - onClick(item: any) { | |
45 | + onClick(item: Object) { | |
43 | 46 | this.setValue(item); |
44 | 47 | this.params.api.stopEditing(); |
45 | 48 | } | ... | ... |
src/app/components/renderer.component.ts
... | ... | @@ -6,23 +6,28 @@ import { RegionSelectList } from '../models/regionselectlist'; |
6 | 6 | |
7 | 7 | @Component({ |
8 | 8 | selector: 'render-cell', |
9 | - template: `<span *ngIf="this.region">{{this.region.name}}</span>` | |
9 | + template: `<span *ngIf="this.model">{{this.model[this.labelCol]}}</span>` | |
10 | 10 | }) |
11 | 11 | export class RendererComponent implements AgRendererComponent { |
12 | 12 | private params: any; |
13 | - private region: RegionSelectList; | |
13 | + private valueCol: string = 'id'; | |
14 | + private labelCol: string = 'name'; | |
15 | + private model: Object = null; | |
14 | 16 | agInit(params: any): void { |
15 | 17 | this.params = params; |
16 | - console.log(params); | |
18 | + if (params.colDef.cellEditorParams && params.colDef.cellEditorParams.valueCol) { | |
19 | + this.valueCol = params.colDef.cellEditorParams.valueCol; | |
20 | + } | |
21 | + if (params.colDef.cellEditorParams && params.colDef.cellEditorParams.labelCol) { | |
22 | + this.labelCol = params.colDef.cellEditorParams.labelCol; | |
23 | + } | |
17 | 24 | this.setValue(params); |
18 | 25 | } |
19 | 26 | refresh(params: any): void { |
20 | 27 | this.params = params; |
21 | - console.log(params); | |
22 | 28 | this.setValue(params); |
23 | 29 | } |
24 | 30 | private setValue(params) { |
25 | - this.region = params.value; | |
26 | - console.log(params); | |
31 | + this.model = params.value; | |
27 | 32 | } |
28 | 33 | } | ... | ... |
src/app/pages/statements/components/busStop2/busStop2.component.ts