11import { Component , OnInit , QueryList , ViewChildren } from '@angular/core' ;
22import { IgxSimpleComboComponent , ISimpleComboSelectionChangingEventArgs } from 'igniteui-angular' ;
3- import { City , Country , getCitiesByCountry , getCountries , Region } from '../../data/cities15000-regions-countries' ;
3+ import { Country , getCitiesByCountry , getCountries } from '../../data/cities15000-regions-countries' ;
44import { 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 ;
@@ -30,62 +30,64 @@ 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 ] ;
3637 const nextCityCombo = this . combos . filter (
3738 ( combo ) => combo . id === 'city-' + ID
3839 ) [ 0 ] ;
3940 this . clearOldData ( cell , nextRegionCombo , nextCityCombo ) ;
40- this . selectedCountry = e . newValue as Country ;
41+ this . selectedCountryName = e . newValue ;
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 ( ( ) => {
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- document . getElementById ( 'region-progress-' + ID ) . style . visibility = 'hidden' ;
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
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 ] ;
6263 this . clearOldData ( cell , null , cityCombo ) ;
6364
64- this . selectedRegion = e . newValue as Region ;
65+ this . selectedRegionName = e . newValue ;
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 ( ( ) => {
73- cityCombo . data = getCitiesByCountry ( [ this . selectedCountry ?. name ] ) . filter (
74- ( c ) => c . region === this . selectedRegion ?. name
71+ cityCombo . data = getCitiesByCountry ( [ this . selectedCountryName ] ) . filter (
72+ ( c ) => c . region === this . selectedRegionName
7573 ) ;
76- document . getElementById (
77- 'city-progress-' + cell . row . data . ID
78- ) . style . visibility = 'hidden' ;
74+ cell . row . data . loadingCity = false ;
7975 } , this . loadingTime ) ;
80- this . selectedCity = null ;
76+ this . selectedCityId = null ;
8177 this . loadingTime = 0 ;
8278 }
79+ public cityChanging ( e : ISimpleComboSelectionChangingEventArgs , cell ) {
80+ cell . update ( e . newValue ) ;
81+ this . selectedCityId = e . newValue ;
82+ }
8383
8484 private clearOldData ( cell , RegionCombo , CityCombo ) {
8585 const nextCellIndex = cell . column . visibleIndex + 1 ;
8686 cell . row . cells [ nextCellIndex ] . update ( '' ) ;
8787
88- if ( CityCombo !== null ) CityCombo . data = [ ] ;
88+ if ( CityCombo !== null ) {
89+ CityCombo . data = [ ] ;
90+ }
8991 if ( RegionCombo !== null ) {
9092 RegionCombo . data = [ ] ;
9193 cell . row . cells [ nextCellIndex + 1 ] . update ( '' ) ;
0 commit comments