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

Get / Set item by value

Thread ID:

Created:

Updated:

Platform:

Replies:

147157 Sep 3,2019 10:43 AM UTC Sep 5,2019 01:13 PM UTC JavaScript - EJ 2 3
loading
Tags: DropDownList
Oka Sugandi
Asked On September 3, 2019 10:43 AM UTC

Hi all,
I have simple data source like this:

let ds = [
                        {
                            value: "value1",
                            text: "Value no 1"
                        },
                        {
                            value: "value2",
                            text: "Value no 2"
                        }
];

and I instantiate ej dropdownlist using that data source.
And then I want to select the item using the value (not the text).

This code does not work:
{
value: "value2"
}

But this code works:
{
value: "Value no 2"
}

Also getter, when I want to know what is the selected value, the .value is the same as the .text..
How I can achieve get/set using value not text?

Thank you.


Narayanasamy Panneer Selvam [Syncfusion]
Replied On September 5, 2019 03:48 AM UTC

Hi Oka, 
 
Greetings from Syncfusion support. 
 
Based on the code, we are not clear whether you are using EJ1 or EJ2. As you have mentioned “*EJ DropDownList*”, we have prepared a sample with EJ1 DropDownList for setting and getting value. You need to map the value field so that this will work fine. You can get the selected value by getSelectedValue() method. 
 
$(function () { 
    // declaration 
    ds = [ 
        { 
            value: "value1", 
            text: "Value no 1" 
        }, 
        { 
            value: "value2", 
            text: "Value no 2" 
        } 
    ]; 
    $('#bikeList').ejDropDownList({ 
        dataSource: ds, 
        fields: { text: "text", value: "value" }, 
        value: "value2" 
    }); 
}); 
function get() { 
    var ddlObj = $("#bikeList").data("ejDropDownList"); 
    alert(ddlObj.getSelectedValue()); 
} 
 
 
Please let us know if you have any concern on this. 
 
Regards,  
Narayanasamy P.  


Oka Sugandi
Replied On September 5, 2019 03:58 AM UTC

Thank you for your reply.
I am using EJ2 ES 5.
Would you like to give sample for EJ2 ES5?
Thank you.

Narayanasamy Panneer Selvam [Syncfusion]
Replied On September 5, 2019 01:13 PM UTC

Hi Oka, 
 
Thanks for your update. 
 
As per your request, we have prepared same sample in ej2. 
In this sample we can get the selected item using value property. 
Please let us know if you need any further assistance on this. 
 
Regards,  
Narayanasamy P.  


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