|
<ejs-dropdownlist id='games' #sample [dataSource]='countries' [fields]='fields' allowFiltering='true' [placeholder]='waterMark' (filtering)='onFiltering($event)' [popupHeight]='height'>
<ng-template #itemTemplate let-data>
<div>
<div class="name"> {{data.Description}}- {{data.Code}} </div>
</div>
</ng-template>
</ejs-dropdownlist>
|
|
public onFiltering(e) {
let predicate = new Predicate('Description', 'startswith', e.text, true);
predicate = predicate.or('Code', 'startswith', e.text,true);
let query: Query = new Query();
//frame the query based on search string with filter type.
query = (e.text !== '' ) ? query.where(predicate) : query;
//pass the filter data source, filter query to updateData method.
e.updateData(this.countries, query);
}
|
Hi Dileep,
Greetings from Syncfusion support.
Query 1: I have a array of object with Code, Description, Id. and i want to display both Code and description in the dropdown with CodeSolution:You can achieve the requested requirement using itemTemplate property in the DropDownList component. Refer to the code below,[app.component.html]
<ejs-dropdownlist id='games' #sample [dataSource]='countries' [fields]='fields' allowFiltering='true' [placeholder]='waterMark' (filtering)='onFiltering($event)' [popupHeight]='height'><ng-template #itemTemplate let-data><div><div class="name"> {{data.Description}}- {{data.Code}} </div></div></ng-template></ejs-dropdownlist>
If you want to customize the selected value that displayed in the input element then, it can be achieved using valueTemplate property. Refer to the ug link below.
Query 2: also must be able to filter either of themSolution:If you want to filter the items based on multiple fields, we suggest using the ‘Predicate’ of dataManager in the filtering event. Refer to the code below,
public onFiltering(e) {let predicate = new Predicate('Description', 'startswith', e.text, true);predicate = predicate.or('Code', 'startswith', e.text,true);let query: Query = new Query();//frame the query based on search string with filter type.query = (e.text !== '' ) ? query.where(predicate) : query;//pass the filter data source, filter query to updateData method.e.updateData(this.countries, query);}
Please find the sample below,
Kindly check with the above sample. Please get back us if you need further assistance.
Regards,Sevvandhi N
Hi Dileep,
Greetings from Syncfusion support.
Query 1: I have a array of object with Code, Description, Id. and i want to display both Code and description in the dropdown with CodeSolution:You can achieve the requested requirement using itemTemplate property in the DropDownList component. Refer to the code below,[app.component.html]
<ejs-dropdownlist id='games' #sample [dataSource]='countries' [fields]='fields' allowFiltering='true' [placeholder]='waterMark' (filtering)='onFiltering($event)' [popupHeight]='height'><ng-template #itemTemplate let-data><div><div class="name"> {{data.Description}}- {{data.Code}} </div></div></ng-template></ejs-dropdownlist>
If you want to customize the selected value that displayed in the input element then, it can be achieved using valueTemplate property. Refer to the ug link below.
Query 2: also must be able to filter either of themSolution:If you want to filter the items based on multiple fields, we suggest using the ‘Predicate’ of dataManager in the filtering event. Refer to the code below,
public onFiltering(e) {let predicate = new Predicate('Description', 'startswith', e.text, true);predicate = predicate.or('Code', 'startswith', e.text,true);let query: Query = new Query();//frame the query based on search string with filter type.query = (e.text !== '' ) ? query.where(predicate) : query;//pass the filter data source, filter query to updateData method.e.updateData(this.countries, query);}
Please find the sample below,
Kindly check with the above sample. Please get back us if you need further assistance.
Regards,Sevvandhi N
Hi,Thanks for the reply, but we are creating dynamic dropdown in .TS file. How can i append the fields or the itemTemplate.dropDownListEdit = {create: () => {ele = document.createElement('input');return ele;},read: () => {return dropDownList.text;},destroy: () => {dropDownList.destroy();},write: (args: { rowData: object, column: Column }) => {dropDownList = new DropDownList({dataSource: idx === 0 ? this.parentDdlData : [],allowFiltering: true,fields: { value: 'id', text: 'description' },itemTemplate: ,// itemTemplate: this.dropDownDisplay.elementRef.nativeElement ,change: () => {let tempQuery: Query = new Query().where('id', 'equal', dropDownList.value);this.getGridDropdownData(tempQuery.queries[0].e.value).pipe(takeUntil(this.unSubscribe)).subscribe(res => {this.validationData = res.data;if (this.editDropDowns[idx + 1]) {this.editDropDowns[idx + 1].enabled = true;this.editDropDowns[idx + 1].text = null;this.editDropDowns[idx + 1].dataSource = res.data;this.editDropDowns[idx + 1].dataBind();}});},actionComplete: () => false,enabled: idx !== 0 ? false : true,placeholder: 'Select ' + ctrl,floatLabelType: 'Never'});dropDownList.appendTo(ele);this.editDropDowns.push(dropDownList);}}
|
this.editparams = {
create: () => {
this.elem = document.createElement("input");
return this.elem;
},
read: () => {
return this.dropObj.text;
},
destroy: () => {
this.dropObj.destroy();
},
write: (args: { rowData: object; column: Column }) => {
this.dropObj = new DropDownList({
dataSource: this.country,
allowFiltering: true,
filtering: this.onFiltering.bind(this),
itemTemplate: "<div><div class='name'>${CountryName}-${CountryId}</div></div>",
fields: { value: "CountryId", text: "CountryName" },
text: args.rowData[args.column.field]
});
this.dropObj.appendTo(this.elem);
}
}; |
Hi Dileep,
Greetings from Syncfusion support.
Query 1: I have a array of object with Code, Description, Id. and i want to display both Code and description in the dropdown with CodeSolution:You can achieve the requested requirement using itemTemplate property in the DropDownList component. Refer to the code below,[app.component.html]
<ejs-dropdownlist id='games' #sample [dataSource]='countries' [fields]='fields' allowFiltering='true' [placeholder]='waterMark' (filtering)='onFiltering($event)' [popupHeight]='height'><ng-template #itemTemplate let-data><div><div class="name"> {{data.Description}}- {{data.Code}} </div></div></ng-template></ejs-dropdownlist>
If you want to customize the selected value that displayed in the input element then, it can be achieved using valueTemplate property. Refer to the ug link below.
Query 2: also must be able to filter either of themSolution:If you want to filter the items based on multiple fields, we suggest using the ‘Predicate’ of dataManager in the filtering event. Refer to the code below,
public onFiltering(e) {let predicate = new Predicate('Description', 'startswith', e.text, true);predicate = predicate.or('Code', 'startswith', e.text,true);let query: Query = new Query();//frame the query based on search string with filter type.query = (e.text !== '' ) ? query.where(predicate) : query;//pass the filter data source, filter query to updateData method.e.updateData(this.countries, query);}
Please find the sample below,
Kindly check with the above sample. Please get back us if you need further assistance.
Regards,Sevvandhi N
Hi,Thanks for the reply, but we are creating dynamic dropdown in .TS file. How can i append the fields or the itemTemplate.dropDownListEdit = {create: () => {ele = document.createElement('input');return ele;},read: () => {return dropDownList.text;},destroy: () => {dropDownList.destroy();},write: (args: { rowData: object, column: Column }) => {dropDownList = new DropDownList({dataSource: idx === 0 ? this.parentDdlData : [],allowFiltering: true,fields: { value: 'id', text: 'description' },itemTemplate: ,// itemTemplate: this.dropDownDisplay.elementRef.nativeElement ,change: () => {let tempQuery: Query = new Query().where('id', 'equal', dropDownList.value);this.getGridDropdownData(tempQuery.queries[0].e.value).pipe(takeUntil(this.unSubscribe)).subscribe(res => {this.validationData = res.data;if (this.editDropDowns[idx + 1]) {this.editDropDowns[idx + 1].enabled = true;this.editDropDowns[idx + 1].text = null;this.editDropDowns[idx + 1].dataSource = res.data;this.editDropDowns[idx + 1].dataBind();}});},actionComplete: () => false,enabled: idx !== 0 ? false : true,placeholder: 'Select ' + ctrl,floatLabelType: 'Never'});dropDownList.appendTo(ele);this.editDropDowns.push(dropDownList);}}
|
this.editparams = {
.
.
write: (args: { rowData: object; column: Column }) => {
this.dropObj = new DropDownList({
.
.
itemTemplate: "<div><div class='name'>${CountryName}-${CountryId}</div></div>",
valueTemplate: "<span>${CountryName}-${CountryId}</span>"
});
this.dropObj.appendTo(this.elem);
}
}; |