11import { 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' ;
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 ;
@@ -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