Commit 354380553529351bd975ba3a80d439b53f54a153
1 parent
198b5d4d
refactor bus stop
Showing
3 changed files
with
15 additions
and
3 deletions
Show diff stats
src/app/components/editor.component.ts
| ... | ... | @@ -6,7 +6,9 @@ import { AgEditorComponent } from 'ag-grid-ng2/main'; |
| 6 | 6 | selector: 'editor-cell', |
| 7 | 7 | template: ` |
| 8 | 8 | <div #container> |
| 9 | - <p *ngFor="let item of data" (click)="onClick(item)" >{{item[this.params.labelCol]}}</p> | |
| 9 | + <p *ngFor="let item of data" (click)="onClick(item[this.params.valueCol])" > | |
| 10 | + {{item[this.params.labelCol]}} | |
| 11 | + </p> | |
| 10 | 12 | </div> |
| 11 | 13 | ` |
| 12 | 14 | }) | ... | ... |
src/app/components/renderer.component.ts
| ... | ... | @@ -6,13 +6,14 @@ import { RegionSelectList } from '../models/regionselectlist'; |
| 6 | 6 | |
| 7 | 7 | @Component({ |
| 8 | 8 | selector: 'render-cell', |
| 9 | - template: `<span *ngIf="this.model">{{this.model[this.labelCol]}}</span>` | |
| 9 | + template: `<span *ngIf="this.model">{{this.label}}</span>` | |
| 10 | 10 | }) |
| 11 | 11 | export class RendererComponent implements AgRendererComponent { |
| 12 | 12 | private params: any; |
| 13 | 13 | private valueCol: string = 'id'; |
| 14 | 14 | private labelCol: string = 'name'; |
| 15 | 15 | private model: Object = null; |
| 16 | + private label: string = null; | |
| 16 | 17 | agInit(params: any): void { |
| 17 | 18 | this.params = params; |
| 18 | 19 | if (params.colDef.cellEditorParams && params.colDef.cellEditorParams.valueCol) { |
| ... | ... | @@ -29,5 +30,14 @@ export class RendererComponent implements AgRendererComponent { |
| 29 | 30 | } |
| 30 | 31 | private setValue(params) { |
| 31 | 32 | this.model = params.value; |
| 33 | + let label = this.params.colDef.cellEditorParams.data.find((element, index, array) => { | |
| 34 | + if (element[this.valueCol] === params.value) { | |
| 35 | + return true; | |
| 36 | + } | |
| 37 | + }); | |
| 38 | + console.log(label, params); | |
| 39 | + if (label) { | |
| 40 | + this.label = label[this.labelCol]; | |
| 41 | + } | |
| 32 | 42 | } |
| 33 | 43 | } | ... | ... |
src/app/pages/statements/components/busStop2/busStop2.component.ts