1+ import { Component , ViewChild } from '@angular/core' ;
2+ import { Query } from '@syncfusion/ej2-data' ;
3+ import { DropDownListComponent } from '@syncfusion/ej2-ng-dropdowns' ;
4+
5+ @Component ( {
6+ selector : 'control-content' ,
7+ templateUrl : 'cascading.html' ,
8+ styleUrls : [ 'dropdownlist.css' ]
9+ } )
10+
11+ export class CascadingDropDownListComponent {
12+ public country : { [ key : string ] : Object } [ ] = [
13+ { countryName : 'United States' , countryId : '1' } ,
14+ { countryName : 'Australia' , countryId : '2' }
15+ ] ;
16+ public state : { [ key : string ] : Object } [ ] = [
17+ { stateName : 'New York' , countryId : '1' , stateId : '101' } ,
18+ { stateName : 'Virginia ' , countryId : '1' , stateId : '102' } ,
19+ { stateName : 'Washington' , countryId : '1' , stateId : '103' } ,
20+ { stateName : 'Queensland' , countryId : '2' , stateId : '104' } ,
21+ { stateName : 'Tasmania ' , countryId : '2' , stateId : '105' } ,
22+ { stateName : 'Victoria' , countryId : '2' , stateId : '106' }
23+ ] ;
24+ public cities : { [ key : string ] : Object } [ ] = [
25+ { cityName : 'Albany' , stateId : '101' , cityId : 201 } ,
26+ { cityName : 'Beacon ' , stateId : '101' , cityId : 202 } ,
27+ { cityName : 'Lockport' , stateId : '101' , cityId : 203 } ,
28+ { cityName : 'Alexandria' , stateId : '102' , cityId : 204 } ,
29+ { cityName : 'Hampton ' , stateId : '102' , cityId : 205 } ,
30+ { cityName : 'Emporia' , stateId : '102' , cityId : 206 } ,
31+ { cityName : 'Aberdeen' , stateId : '103' , cityId : 207 } ,
32+ { cityName : 'Colville ' , stateId : '103' , cityId : 208 } ,
33+ { cityName : 'Pasco' , stateId : '103' , cityId : 209 } ,
34+ { cityName : 'Townsville' , stateId : '104' , cityId : 210 } ,
35+ { cityName : 'Brisbane ' , stateId : '104' , cityId : 211 } ,
36+ { cityName : 'Cairns' , stateId : '104' , cityId : 212 } ,
37+ { cityName : 'Hobart' , stateId : '105' , cityId : 213 } ,
38+ { cityName : 'Launceston ' , stateId : '105' , cityId : 214 } ,
39+ { cityName : 'Devonport' , stateId : '105' , cityId : 215 } ,
40+ { cityName : 'Melbourne' , stateId : '106' , cityId : 216 } ,
41+ { cityName : 'Healesville ' , stateId : '106' , cityId : 217 } ,
42+ { cityName : 'Geelong' , stateId : '106' , cityId : 218 }
43+ ] ;
44+ public countryFields : Object = { value : 'countryId' , text : 'countryName' } ;
45+ public stateFields : Object = { value : 'stateId' , text : 'stateName' } ;
46+ public cityFields : Object = { text : 'cityName' , value : 'cityId' } ;
47+ public countryWaterMark : string = 'Select a country' ;
48+ public stateWaterMark : string = 'Select a state' ;
49+ public cityWaterMark : string = 'Select a city' ;
50+ @ViewChild ( 'countryList' )
51+ public countryObj : DropDownListComponent ;
52+ @ViewChild ( 'stateList' )
53+ public stateObj : DropDownListComponent ;
54+ @ViewChild ( 'cityList' )
55+ public cityObj : DropDownListComponent ;
56+ public onChange1 ( ) : void {
57+ this . stateObj . enabled = true ;
58+ let tempQuery : Query = new Query ( ) . where ( 'countryId' , 'equal' , this . countryObj . value ) ;
59+ this . stateObj . query = tempQuery ;
60+ this . stateObj . text = null ;
61+ this . stateObj . dataBind ( ) ;
62+ this . cityObj . text = null ;
63+ this . cityObj . enabled = false ;
64+ this . cityObj . dataBind ( ) ;
65+ }
66+ public onChange2 ( ) : void {
67+ this . cityObj . enabled = true ;
68+ let tempQuery1 : Query = new Query ( ) . where ( 'stateId' , 'equal' , this . stateObj . value ) ;
69+ this . cityObj . query = tempQuery1 ;
70+ this . cityObj . text = null ;
71+ this . cityObj . dataBind ( ) ;
72+ }
73+ }
0 commit comments