How to refresh listbox automatically when its datasource get updated?

I have a listbox as shown below

<ejs-listbox [dataSource]="this.data" height='250'></ejs-listbox>

Array 'data' is declared in the typescript code:

public data = ["item1", "item2", "item3"];

There is a button in the page. When clicking it, a new item is added into data.
onButtonClick() {
     this.data.push("item4");
}

The problem is: my listbox does not refresh automatically to reflect the update of its data source. I have to switch to another page and switch back in order to see the change.

What is the correct way to achieve the automatic refresh of listbox? Thanks.

3 Replies 1 reply marked as answer

AS Aravinthan Seetharaman Syncfusion Team January 15, 2021 05:59 AM UTC

Hi Huifei, 
 
Thanks for contacting Syncfusion Support. 
 
We have checked your reported query, and we can achieve the automatic refresh of listbox by using refresh() method as like below. 
 
 
onButtonClick() { 
    this.data.push("item4"); 
    this.listObj.refresh(); 
  } 
 
 
And we have AddItems() method for add Items to listbox, please refer the below link. 
 
 
 
Could you please check whether the details are fulfilling your requirement, and get back to us, if you need assistance on this. 
 
Regards, 
Aravinthan S 


Marked as answer

HR Huifei Rao January 15, 2021 07:30 PM UTC

Thanks. It (the refresh method) works as expected!




AS Aravinthan Seetharaman Syncfusion Team January 18, 2021 05:34 AM UTC

Hi Huifei, 
 
Thanks for the update. 
 
We are happy to hear that your issue has been resolved. Please feel free to contact us, if you need any further assistance on this. 
 
Regards, 
Aravinthan S 


Loader.
Up arrow icon