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,20 +2,18 @@ import { Component, ViewContainerRef, ViewChild, AfterViewInit } from '@angular/ | ||
2 | 2 | ||
3 | import { AgEditorComponent } from 'ag-grid-ng2/main'; | 3 | import { AgEditorComponent } from 'ag-grid-ng2/main'; |
4 | 4 | ||
5 | -import { RegionSelectList } from '../models/regionselectlist'; | ||
6 | - | ||
7 | @Component({ | 5 | @Component({ |
8 | selector: 'editor-cell', | 6 | selector: 'editor-cell', |
9 | template: ` | 7 | template: ` |
10 | <div #container> | 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 | </div> | 10 | </div> |
13 | ` | 11 | ` |
14 | }) | 12 | }) |
15 | export class EditorComponent implements AgEditorComponent, AfterViewInit { | 13 | export class EditorComponent implements AgEditorComponent, AfterViewInit { |
16 | @ViewChild('container', {read: ViewContainerRef}) public container; | 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 | private params: any; | 17 | private params: any; |
20 | ngAfterViewInit() { | 18 | ngAfterViewInit() { |
21 | this.container.element.nativeElement.focus(); | 19 | this.container.element.nativeElement.focus(); |
@@ -23,8 +21,13 @@ export class EditorComponent implements AgEditorComponent, AfterViewInit { | @@ -23,8 +21,13 @@ export class EditorComponent implements AgEditorComponent, AfterViewInit { | ||
23 | 21 | ||
24 | agInit(params: any): void { | 22 | agInit(params: any): void { |
25 | this.params = params; | 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 | this.data = params.data || []; | 30 | this.data = params.data || []; |
27 | - // this.setHappy(params.value === "Happy"); | ||
28 | } | 31 | } |
29 | 32 | ||
30 | getValue(): any { | 33 | getValue(): any { |
@@ -35,11 +38,11 @@ export class EditorComponent implements AgEditorComponent, AfterViewInit { | @@ -35,11 +38,11 @@ export class EditorComponent implements AgEditorComponent, AfterViewInit { | ||
35 | return true; | 38 | return true; |
36 | } | 39 | } |
37 | 40 | ||
38 | - setValue(item: any): void { | 41 | + setValue(item: Object): void { |
39 | this.item = item; | 42 | this.item = item; |
40 | } | 43 | } |
41 | 44 | ||
42 | - onClick(item: any) { | 45 | + onClick(item: Object) { |
43 | this.setValue(item); | 46 | this.setValue(item); |
44 | this.params.api.stopEditing(); | 47 | this.params.api.stopEditing(); |
45 | } | 48 | } |
src/app/components/renderer.component.ts
@@ -6,23 +6,28 @@ import { RegionSelectList } from '../models/regionselectlist'; | @@ -6,23 +6,28 @@ import { RegionSelectList } from '../models/regionselectlist'; | ||
6 | 6 | ||
7 | @Component({ | 7 | @Component({ |
8 | selector: 'render-cell', | 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 | export class RendererComponent implements AgRendererComponent { | 11 | export class RendererComponent implements AgRendererComponent { |
12 | private params: any; | 12 | private params: any; |
13 | - private region: RegionSelectList; | 13 | + private valueCol: string = 'id'; |
14 | + private labelCol: string = 'name'; | ||
15 | + private model: Object = null; | ||
14 | agInit(params: any): void { | 16 | agInit(params: any): void { |
15 | this.params = params; | 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 | this.setValue(params); | 24 | this.setValue(params); |
18 | } | 25 | } |
19 | refresh(params: any): void { | 26 | refresh(params: any): void { |
20 | this.params = params; | 27 | this.params = params; |
21 | - console.log(params); | ||
22 | this.setValue(params); | 28 | this.setValue(params); |
23 | } | 29 | } |
24 | private setValue(params) { | 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
@@ -85,7 +85,9 @@ export class BusStop2 { | @@ -85,7 +85,9 @@ export class BusStop2 { | ||
85 | cellEditorFramework: EditorComponent, | 85 | cellEditorFramework: EditorComponent, |
86 | cellRendererFramework: RendererComponent, | 86 | cellRendererFramework: RendererComponent, |
87 | cellEditorParams: { | 87 | cellEditorParams: { |
88 | - data: this.regions | 88 | + data: this.regions, |
89 | + valueCol: 'regionId', | ||
90 | + labelCol: 'name' | ||
89 | } | 91 | } |
90 | }, | 92 | }, |
91 | { | 93 | { |