Cascading Scenario
The igx-combo and igx-select exposes events, properties and methods that allows users to easily construct cascading scenarios, either using one of the controls or both of them.
Demo
The following sample demonstrates a scenario where two igx-select and igx-combo components are used:
Usage
To get started import the IgxComboModule, IgxSelectModule in the app.module.ts file:
// app.module.ts
...
import { IgxComboModule, IgxSelectModule } from 'igniteui-angular';
@NgModule({
...
imports: [..., IgxComboModule, IgxSelectModule],
...
})
export class AppModule {}
The sample below uses an igx-combo and two igx-select components. The API of the both components are used to get selected item from one and load data source for the next either select or combo, clear selection or reset data source.
<igx-select type="box" #cntr placeholder="Choose Country..."
(onSelection)="selectCountry($event)" [(ngModel)]="location.country">
<igx-select-item *ngFor="let c of countryData" [value]="c"> {{ c }} </igx-select-item>
</igx-select>
<igx-select type="box" #prvnc placeholder="Choose Province..." [disabled]="!cntr.value"
(onSelection)="selectProvince($event)" [(ngModel)]="location.province">
<igx-select-item *ngFor="let p of provinceData" [value]="p"> {{ p }} </igx-select-item>
</igx-select>
<igx-combo #twn [itemsMaxHeight]="225" [data]="townData" [disabled]="!prvnc.value"
placeholder="Choose Town..." searchPlaceholder="Search..." [allowCustomValues]="false"
[(ngModel)]="location.towns">
</igx-combo>
import { Component } from "@angular/core";
import { data } from "./local-data";
@Component({
selector: "app-combo",
styleUrls: ["./cascading-combos.component.scss"],
templateUrl: "./cascading-combos.component.html"
})
export class CascadingCombos {
public location: { country: string, province: string, towns: string[] } = { country: "", province: "", towns: [] };
public data = data;
public countryData = [];
public provinceData = [];
public townData = [];
constructor() {
this.countryData = Object.keys(data);
}
public selectCountry(args) {
this.provinceData = Object.keys(this.data[args.newSelection.value]);
this.location.province = "";
this.location.towns = [];
}
public selectProvince(args) {
this.townData = this.data[this.location.country][args.newSelection.value];
this.location.towns = [this.townData[0]];
}
}
Additional Resources
- Combo Features
- Combo Remote Binding
- Combo Templates
- Template Driven Forms Integration
- Reactive Forms Integration
- IgxOverlay
Our community is active and always welcoming to new ideas.