|
@Component({
selector: 'my-app',
template: `<ejs-checkbox label="Default" #chkbox1 [checked]="true" (change)="onChange($event)"></ejs-checkbox>
<div>
<ejs-checkbox label="Another" #chkbox2 (change)="onChange1($event)"></ejs-checkbox>
</div>
<ejs-dropdownlist id='ddlelement' #samples [dataSource]='data' [fields]='fields' [placeholder]='text'></ejs-dropdownlist>`,
})
export class AppComponent {
name = 'Angular 6';
// defined the array of data
public data: { [key: string]: Object }[] = [ { Id: 'game1', Game:'Badminton' },
{ Id: 'game2', Game: 'Football' }, { Id: 'game3', Game:'Tennis' }];
public data1: { [key: string]: Object }[] = [ { Id: 'game4', Game:'Cricket' },
{ Id: 'game5', Game: 'Soccer' }, { Id: 'game6', Game:'Golf' }];
// maps the appropriate column to fields property
public fields: Object = { text: 'Game', value: 'Id' };
//set the placeholder to DropDownList input
public text: string = "Select a game";
@ViewChild('samples')
public dropDownListObject: DropDownListComponent;
@ViewChild('chkbox1')
public chkbox1Obj: CheckBoxComponent;
@ViewChild('chkbox2')
public chkbox2Obj: CheckBoxComponent;
onChange(args: ChangeEventArgs){
let data3: any= this.data.concat(this.data1);
debugger
if(args.checked)
{
if(this.chkbox2Obj.checked)
this.dropDownListObject.dataSource=data3; // datasource append based on the checkbox status
else
this.dropDownListObject.dataSource=this.data;
}
else
{
if(this.chkbox2Obj.checked)
this.dropDownListObject.dataSource=this.data1;
else
this.dropDownListObject.dataSource=[];
}
}
onChange1(args: ChangeEventArgs){
let data3: any= this.data.concat(this.data1);
debugger
if(args.checked)
{
if(this.chkbox1Obj.checked)
this.dropDownListObject.dataSource=data3;
else
this.dropDownListObject.dataSource=this.data1;
}
else
{
if(this.chkbox1Obj.checked)
this.dropDownListObject.dataSource=this.data;
else
this.dropDownListObject.dataSource=[];
}
}
}
|
Hi Ali Kholmatov,Thanks for contacting Syncfusion Support.Based on the checkbox status, the dataSource of the DropDownList component gets changed.We suggest you to use change event of the CheckBox Component. Please refer to the code block below,
@Component({selector: 'my-app',template: `<ejs-checkbox label="Default" #chkbox1 [checked]="true" (change)="onChange($event)"></ejs-checkbox><div><ejs-checkbox label="Another" #chkbox2 (change)="onChange1($event)"></ejs-checkbox></div><ejs-dropdownlist id='ddlelement' #samples [dataSource]='data' [fields]='fields' [placeholder]='text'></ejs-dropdownlist>`,})export class AppComponent {name = 'Angular 6';// defined the array of datapublic data: { [key: string]: Object }[] = [ { Id: 'game1', Game:'Badminton' },{ Id: 'game2', Game: 'Football' }, { Id: 'game3', Game:'Tennis' }];public data1: { [key: string]: Object }[] = [ { Id: 'game4', Game:'Cricket' },{ Id: 'game5', Game: 'Soccer' }, { Id: 'game6', Game:'Golf' }];// maps the appropriate column to fields propertypublic fields: Object = { text: 'Game', value: 'Id' };//set the placeholder to DropDownList inputpublic text: string = "Select a game";@ViewChild('samples')public dropDownListObject: DropDownListComponent;@ViewChild('chkbox1')public chkbox1Obj: CheckBoxComponent;@ViewChild('chkbox2')public chkbox2Obj: CheckBoxComponent;onChange(args: ChangeEventArgs){let data3: any= this.data.concat(this.data1);debuggerif(args.checked){if(this.chkbox2Obj.checked)this.dropDownListObject.dataSource=data3; // datasource append based on the checkbox statuselsethis.dropDownListObject.dataSource=this.data;}else{if(this.chkbox2Obj.checked)this.dropDownListObject.dataSource=this.data1;elsethis.dropDownListObject.dataSource=[];}}onChange1(args: ChangeEventArgs){let data3: any= this.data.concat(this.data1);debuggerif(args.checked){if(this.chkbox1Obj.checked)this.dropDownListObject.dataSource=data3;elsethis.dropDownListObject.dataSource=this.data1;}else{if(this.chkbox1Obj.checked)this.dropDownListObject.dataSource=this.data;elsethis.dropDownListObject.dataSource=[];}}}If your requirement is not meet,
- Kindly send us the scenario of the error
- Kindly send us the error details
- Kindly send the screenshot of the error
Please refer to the below sample,Regards,Ilakkiya B
|
private updateSelectionList() {
let res: SelectItem<AccountInfo>[] = [];
if (this.selectBing && this._bingAccounts.length > 0) {
res = [...res, ...this.transformAccounts(this._bingAccounts, 'Bing', res.length)];
}
if (this.selectGoogle && this._googleAccounts.length > 0) {
res = [...res, ...this.transformAccounts(this._googleAccounts, 'Google', res.length)];
}
if (res.length > 0) {
const selectAll = new SelectItemAll<AccountInfo>();
selectAll.text = `All accounts (${res.length})`;
selectAll.id = -1;
res = [selectAll, ...res];
this.data = res; // assign dataSource before setting value
this.selectedAccountId = selectAll.id;
} else {
this.selectedAccountId = null;
}
} |