We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

How to a clear an ejs-listbox

I have no issues with assigning a datasource to a listbox:
ie.

…..
            .done(function (result) {
                var lstSignedUp = document.getElementById('lstSignedUp').ej2_instances[0];
                lstSignedUp.dataSource = result;
                lstSignedUp.dataBind
            })

But how do I un-assign the datasource so the listbox displays no items?
I tried this, but nothing happens,

        let lstSignedUp = document.getElementById('lstSignedUp').ej2_instances[0];
        lstSignedUp.dataSource = null;
        lstSignedUp.dataBind

I've also tried:
        lstSignedUp.listData = null    //again the list box does not empty.

Thanks,
Mike


3 Replies

VK Vinoth Kumar Sundara Moorthy Syncfusion Team August 1, 2019 11:07 AM UTC

Hi Mike, 
 
Good day to you. 
 
We have checked your provided code snippet and we suggest you use refresh method instead of dataBind to clear the ListBox as like in the below code example, 
 
Code Example 
function onCreate() { 
    var obj = document.getElementById('listbox').ej2_instances[0]; 
    obj.dataSource = null; 
    obj.refresh(); 
} 
 
For your convenience, we have prepared a sample and the same can be downloaded from below link, 
 
Could you please check the above sample and get back to us if you need any further assistance on this? 
 
Regards, 
Vinoth Kumar S 



ML Michael Lambert August 1, 2019 12:51 PM UTC

Worked
Thanks!


VK Vinoth Kumar Sundara Moorthy Syncfusion Team August 2, 2019 07:40 AM UTC

Hi Mike, 
  
You are most welcome. Please feel free to contact us if you need any further assistance on Syncfusion components. 
  
Regards, 
Vinoth Kumar S 


Loader.
Live Chat Icon For mobile
Up arrow icon