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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback
Essential JS2

Syncfusion jQuery based widgets are no longer in active development. Switch to our pure JavaScript based next generation Essential JS 2 library.

Change the datasource programmatically

Thread ID:

Created:

Updated:

Platform:

Replies:

142324 Jan 28,2019 05:02 PM UTC Jan 29,2019 07:36 AM UTC jQuery 1
loading
Tags: ejDropDownList
Marco Giorgi
Asked On January 28, 2019 05:02 PM UTC

I have a dropdownlist that I create with the following code:

$('td#' + selectedCol + ' .units').ejDropDownList({
                                                width: 250,
                                                popupHeight: 300,
                                                watermarkText: "Select a unit",
                                                dataSource: unitsOfMeasure,
                                                fields: {
                                                    text: "text",
                                                    value: "value"
                                                }
                                            });

now, when the user click a button, I'd like to change the dataSource and load another set of items, contained in the variable unitOfMeasure2, 
How can I do it in the fastest and most performant way?

Thanks
Best

Prince Oliver [Syncfusion]
Replied On January 29, 2019 07:36 AM UTC

Hi Marco, 

Thank you for contacting Syncfusion support. 

We can use the dataSource property from the control’s instance and assign new data to the control in the button click handler. Kindly refer to the following code snippet. 

<script> 
    var ddlObj, unitsOfMeasure, unitOfMeasure2; 
    ddlObj = $('td#' + selectedCol + ' .units').ejDropDownList({ 
        width: 250, 
        popupHeight: 300, 
        watermarkText: "Select a unit", 
        dataSource: unitsOfMeasure, 
        fields: { 
            text: "text", 
            value: "value" 
        } 
    }).data("ejDropDownList"); 
 
    function btnClick() { 
        ddlObj.setModel({ dataSource: unitOfMeasure2}); 
    } 
</script> 

We have attached a sample for your reference, please find the sample at the following location: https://jsplayground.syncfusion.com/q2cpcg5q 

Please let us know if you need any further assistance on this. 

Regards, 
Prince 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon