Skip to content

Commit e3a652a

Browse files
committed
fix(cascading-combos): bind cell value, ngIf for progress bars
1 parent 58449fc commit e3a652a

2 files changed

Lines changed: 19 additions & 15 deletions

File tree

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
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)"
1112
[displayKey]="'name'" width="100%">
1213
</igx-simple-combo>
1314
</ng-template>
@@ -17,10 +18,10 @@
1718
<div>
1819
<igx-simple-combo [id]="'region-' + cell.row.data.ID"
1920
(selectionChanging)="regionChanging($event, cell)" placeholder="Choose Region..."
20-
[displayKey]="'name'" [(ngModel)]="cell.value"
21-
[disabled]="cell.row.cells[1].value === ''">
21+
[ngModel]="cell.value === '' ? undefined : cell.value" (ngModelChange)="handleCellUpdate($event, cell)"
22+
[displayKey]="'name'" [disabled]="cell.row.cells[1].value === ''">
2223
</igx-simple-combo>
23-
<igx-linear-bar [id]="'region-progress-' + cell.row.data.ID" [style.visibility]="'hidden'"
24+
<igx-linear-bar *ngIf="cell.row.data.loadingRegion" [id]="'region-progress-' + cell.row.data.ID"
2425
type="info" [indeterminate]="true">
2526
</igx-linear-bar>
2627
</div>
@@ -30,9 +31,10 @@
3031
<ng-template igxCell let-cell="cell">
3132
<div>
3233
<igx-simple-combo [id]="'city-' + cell.row.data.ID" placeholder="Choose City..."
33-
[(ngModel)]="cell.value" [displayKey]="'name'" [disabled]="cell.row.cells[2].value === ''">
34+
[ngModel]="cell.value === '' ? undefined : cell.value" (ngModelChange)="handleCellUpdate($event, cell)"
35+
[displayKey]="'name'" [disabled]="cell.row.cells[2].value === ''">
3436
</igx-simple-combo>
35-
<igx-linear-bar [id]="'city-progress-' + cell.row.data.ID" [style.visibility]="'hidden'"
37+
<igx-linear-bar *ngIf="cell.row.data.loadingCity" [id]="'city-progress-' + cell.row.data.ID"
3638
type="info" [indeterminate]="true">
3739
</igx-linear-bar>
3840
</div>

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

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

@@ -30,6 +30,7 @@ export class GridCascadingCombosComponent implements OnInit {
3030

3131
public countryChanging(e: ISimpleComboSelectionChangingEventArgs, cell) {
3232
const ID = cell.row.data.ID;
33+
cell.row.data.loadingRegion = true;
3334
const nextRegionCombo = this.combos.filter(
3435
(combo) => combo.id === 'region-' + ID
3536
)[0];
@@ -40,14 +41,13 @@ export class GridCascadingCombosComponent implements OnInit {
4041
this.selectedCountry = e.newValue as Country;
4142
cell.update(e.newValue ? e.newValue : '');
4243
if (e.newValue) {
43-
document.getElementById('region-progress-' + ID).style.visibility = 'visible';
4444
this.loadingTime = 2000;
4545
}
4646
setTimeout(() => {
4747
nextRegionCombo.data = getCitiesByCountry([this.selectedCountry?.name])
4848
.map((c) => ({ name: c.region, country: c.country }))
4949
.filter((v, i, a) => a.findIndex((r) => r.name === v.name) === i);
50-
document.getElementById('region-progress-' + ID).style.visibility = 'hidden';
50+
cell.row.data.loadingRegion = false;
5151
}, this.loadingTime);
5252
this.selectedRegion = null;
5353
this.selectedCity = null;
@@ -56,6 +56,7 @@ export class GridCascadingCombosComponent implements OnInit {
5656

5757
public regionChanging(e: ISimpleComboSelectionChangingEventArgs, cell) {
5858
const nextComboID = 'city-' + cell.row.data.ID;
59+
cell.row.data.loadingCity = true;
5960
const cityCombo = this.combos.filter(
6061
(combo) => combo.id === nextComboID
6162
)[0];
@@ -64,18 +65,13 @@ export class GridCascadingCombosComponent implements OnInit {
6465
this.selectedRegion = e.newValue as Region;
6566
cell.update(e.newValue ? e.newValue : '');
6667
if (e.newValue) {
67-
document.getElementById(
68-
'city-progress-' + cell.row.data.ID
69-
).style.visibility = 'visible';
7068
this.loadingTime = 2000;
7169
}
7270
setTimeout(() => {
7371
cityCombo.data = getCitiesByCountry([this.selectedCountry?.name]).filter(
7472
(c) => c.region === this.selectedRegion?.name
7573
);
76-
document.getElementById(
77-
'city-progress-' + cell.row.data.ID
78-
).style.visibility = 'hidden';
74+
cell.row.data.loadingCity = false;
7975
}, this.loadingTime);
8076
this.selectedCity = null;
8177
this.loadingTime = 0;
@@ -85,10 +81,16 @@ export class GridCascadingCombosComponent implements OnInit {
8581
const nextCellIndex = cell.column.visibleIndex + 1;
8682
cell.row.cells[nextCellIndex].update('');
8783

88-
if (CityCombo !== null) CityCombo.data = [];
84+
if (CityCombo !== null) {
85+
CityCombo.data = [];
86+
}
8987
if (RegionCombo !== null) {
9088
RegionCombo.data = [];
9189
cell.row.cells[nextCellIndex + 1].update('');
9290
}
9391
}
92+
93+
public handleCellUpdate(value: any, cell: CellType) {
94+
cell.update(value);
95+
}
9496
}

0 commit comments

Comments
 (0)