Skip to content

Commit bf0f12e

Browse files
committed
fix(cascading-combos): assign valueKeys, more changes
1 parent e3a652a commit bf0f12e

2 files changed

Lines changed: 28 additions & 27 deletions

File tree

src/app/grid/grid-cascading-combos/grid-cascading-combos.component.html

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<div class="grid__wrapper">
22
<div class="sample__header">
3-
<igx-grid [igxPreventDocumentScroll]="true" #grid1 [data]="data" [autoGenerate]="false"
4-
width="100%" height="500px" [primaryKey]="'ID'">
3+
<igx-grid [igxPreventDocumentScroll]="true" #grid1 [data]="data" [autoGenerate]="false" width="100%"
4+
height="500px" [primaryKey]="'ID'">
55
<igx-column field="ID" header="ID" [dataType]="'number'" width="50px">
66
</igx-column>
7-
<igx-column field="Country" header="Country" [dataType]="'string'" width="220px">
7+
<igx-column field="Country" header="Country" dataType="string" width="220px">
88
<ng-template igxCell let-cell="cell">
99
<igx-simple-combo [id]="'country-' + cell.row.data.ID" [data]="countriesData"
1010
(selectionChanging)="countryChanging($event, cell)" placeholder="Choose Country..."
11-
[ngModel]="cell.value === '' ? undefined : cell.value" (ngModelChange)="handleCellUpdate($event, cell)"
12-
[displayKey]="'name'" width="100%">
11+
[ngModel]="cell.value === '' ? undefined : cell.value" [valueKey]="'name'" [displayKey]="'name'"
12+
width="100%">
1313
</igx-simple-combo>
1414
</ng-template>
1515
</igx-column>
@@ -18,7 +18,7 @@
1818
<div>
1919
<igx-simple-combo [id]="'region-' + cell.row.data.ID"
2020
(selectionChanging)="regionChanging($event, cell)" placeholder="Choose Region..."
21-
[ngModel]="cell.value === '' ? undefined : cell.value" (ngModelChange)="handleCellUpdate($event, cell)"
21+
[ngModel]="cell.value === '' ? undefined : cell.value" [valueKey]="'name'"
2222
[displayKey]="'name'" [disabled]="cell.row.cells[1].value === ''">
2323
</igx-simple-combo>
2424
<igx-linear-bar *ngIf="cell.row.data.loadingRegion" [id]="'region-progress-' + cell.row.data.ID"
@@ -27,12 +27,13 @@
2727
</div>
2828
</ng-template>
2929
</igx-column>
30-
<igx-column field="City" header="City" width="220px" [editable]="true">
30+
<igx-column field="City" header="City" width="220px" dataType="number">
3131
<ng-template igxCell let-cell="cell">
3232
<div>
3333
<igx-simple-combo [id]="'city-' + cell.row.data.ID" placeholder="Choose City..."
34-
[ngModel]="cell.value === '' ? undefined : cell.value" (ngModelChange)="handleCellUpdate($event, cell)"
35-
[displayKey]="'name'" [disabled]="cell.row.cells[2].value === ''">
34+
(selectionChanging)="cityChanging($event, cell)"
35+
[ngModel]="!cell.value ? undefined : cell.value" [valueKey]="'id'" [displayKey]="'name'"
36+
[disabled]="cell.row.cells[2].value === ''">
3637
</igx-simple-combo>
3738
<igx-linear-bar *ngIf="cell.row.data.loadingCity" [id]="'city-progress-' + cell.row.data.ID"
3839
type="info" [indeterminate]="true">

src/app/grid/grid-cascading-combos/grid-cascading-combos.component.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Component, OnInit, QueryList, ViewChildren } from '@angular/core';
2-
import { CellType, IgxSimpleComboComponent, ISimpleComboSelectionChangingEventArgs } from 'igniteui-angular';
3-
import { City, Country, getCitiesByCountry, getCountries, Region } from '../../data/cities15000-regions-countries';
2+
import { IgxSimpleComboComponent, ISimpleComboSelectionChangingEventArgs } from 'igniteui-angular';
3+
import { Country, getCitiesByCountry, getCountries } from '../../data/cities15000-regions-countries';
44
import { DATA } from '../../data/data';
55

66
@Component({
@@ -12,9 +12,9 @@ export class GridCascadingCombosComponent implements OnInit {
1212
@ViewChildren(IgxSimpleComboComponent)
1313
public combos: QueryList<IgxSimpleComboComponent>;
1414

15-
public selectedCountry: Country;
16-
public selectedRegion: Region;
17-
public selectedCity: City;
15+
public selectedCountryName: string;
16+
public selectedRegionName: string;
17+
public selectedCityId: number;
1818
public countriesData: Country[];
1919
private loadingTime = 0;
2020
public data;
@@ -38,19 +38,19 @@ export class GridCascadingCombosComponent implements OnInit {
3838
(combo) => combo.id === 'city-' + ID
3939
)[0];
4040
this.clearOldData(cell, nextRegionCombo, nextCityCombo);
41-
this.selectedCountry = e.newValue as Country;
41+
this.selectedCountryName = e.newValue;
4242
cell.update(e.newValue ? e.newValue : '');
4343
if (e.newValue) {
4444
this.loadingTime = 2000;
4545
}
4646
setTimeout(() => {
47-
nextRegionCombo.data = getCitiesByCountry([this.selectedCountry?.name])
47+
nextRegionCombo.data = getCitiesByCountry([this.selectedCountryName])
4848
.map((c) => ({ name: c.region, country: c.country }))
4949
.filter((v, i, a) => a.findIndex((r) => r.name === v.name) === i);
50-
cell.row.data.loadingRegion = false;
50+
cell.row.data.loadingRegion = false;
5151
}, this.loadingTime);
52-
this.selectedRegion = null;
53-
this.selectedCity = null;
52+
this.selectedRegionName = null;
53+
this.selectedCityId = null;
5454
this.loadingTime = 0;
5555
}
5656

@@ -62,20 +62,24 @@ export class GridCascadingCombosComponent implements OnInit {
6262
)[0];
6363
this.clearOldData(cell, null, cityCombo);
6464

65-
this.selectedRegion = e.newValue as Region;
65+
this.selectedRegionName = e.newValue;
6666
cell.update(e.newValue ? e.newValue : '');
6767
if (e.newValue) {
6868
this.loadingTime = 2000;
6969
}
7070
setTimeout(() => {
71-
cityCombo.data = getCitiesByCountry([this.selectedCountry?.name]).filter(
72-
(c) => c.region === this.selectedRegion?.name
71+
cityCombo.data = getCitiesByCountry([this.selectedCountryName]).filter(
72+
(c) => c.region === this.selectedRegionName
7373
);
7474
cell.row.data.loadingCity = false;
7575
}, this.loadingTime);
76-
this.selectedCity = null;
76+
this.selectedCityId = null;
7777
this.loadingTime = 0;
7878
}
79+
public cityChanging(e: ISimpleComboSelectionChangingEventArgs, cell) {
80+
cell.update(e.newValue);
81+
this.selectedCityId = e.newValue;
82+
}
7983

8084
private clearOldData(cell, RegionCombo, CityCombo) {
8185
const nextCellIndex = cell.column.visibleIndex + 1;
@@ -89,8 +93,4 @@ export class GridCascadingCombosComponent implements OnInit {
8993
cell.row.cells[nextCellIndex + 1].update('');
9094
}
9195
}
92-
93-
public handleCellUpdate(value: any, cell: CellType) {
94-
cell.update(value);
95-
}
9696
}

0 commit comments

Comments
 (0)