Hi,i am facing issue in filteration of combobox.i have sent you the code ,i have tried.but it is not working the "add item popup" is coming as soon as i am typing any thing in combobox.
could you please take a look on my code and please let me know if i have done any mistake.
"company data " coming as array of objects[{id:'09','name':'Ram'},{id:'09','name':'Ram'}].
another question if there is any method through which when i click on on external button, i can clear the data selected in combobox
<ej-combobox id='comboelement' #remote [dataSource]='data'
[fields]='Fields' [placeholder]='PlaceHolder' [allowFiltering]=true
(filtering)='onFiltering($event)' (select)="onSelectdata($event)" [popupHeight]='height'>
<ng-template #noRecordsTemplate>
<div id="nodata"> No matched item, do you want to add it as new item in list?</div> <button (click)="addNewItem($event)" class="e-control e-btn">Add New Item</button>
</ng-template>
</ej-combobox>
import { ComboBoxComponent } from '@syncfusion/ej2-ng-dropdowns';
@Component({
selector: 'app-component',
templateUrl: './component.component.html',
styleUrls: ['./component.component.css']
})
export class Appcomponent implements OnInit{
@ViewChild('companyremote')
public comboObj: ComboBoxComponent;
public dataSelected: DataI;
ngOnInit() {
// ComboBox
this.data= new DataManager({
url: //url is given,
adaptor: // i have used custom adaptor
crossDomain: true,
headers: //here header is passed
});
this.Fields = { text: 'name', value: 'id' };
this.PlaceHolder = 'Select an item';
}
// item Selection
onSelectdata() {
//functionality written on selection of item using systemevnt args
}
public addNewItem = () => {
// get the typed characters
let customValue: string = (this.comboObj.element.getElementsByClassName('e-input')[0] as HTMLInputElement).value;
//api is called
//here m calling my calling my service by providing obj using custom value ,i am subscribing the response coming from server//.subscribe(response => {
this.comboObj.hidePopup();// hiding the popup
this.comboObj.addItem(response.obj);//adding obj item in combobox
this.comboObj.value = response.obj.name;//seting current selected value as response obj text
});
}
public onFiltering: EmitType<FilteringEventArgs> = (e: FilteringEventArgs) => {
if (e.text === '') {
let query: Query = new Query().select(['name', 'id']);
e.updateData(this.data.executeLocal(query));
} else {
let query: Query = new Query().select(['name', 'id']);
// change the type of filtering
query = (e.text !== '') ? query.where('name', 'startswith', e.text, true) : query;
e.updateData(this.data.executeLocal(query));
}
}
}