This is a migrated thread and some comments may be shown as answers.

Dropdown list API to return non-string selected value

2 Answers 700 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Madhura
Top achievements
Rank 1
Madhura asked on 07 Jul 2014, 10:09 AM
If my datasource has non string values like in the below example (modified the Basic Usage demo code)

$("#color").kendoDropDownList({
    dataTextField: "text",
    dataValueField: "value",
    dataSource: [
       { text: "Black", value: 1 },
       { text: "Orange", value: 2 },
       { text: "Grey", value: 3 }
    ],
    index: 0,
    change: onChange
});

Whenever I change/select another the dropdown option, I try to get the selected item's value using value() method. It always returns a string value.
In this example, it returns "1" or "2" or "3" even if the values are integer and not string.
Is there any other way, I can get the correct values (as integer) ?

2 Answers, 1 is accepted

Sort by
0
Dimiter Madjarov
Telerik team
answered on 07 Jul 2014, 10:44 AM
Hi Madhura,


You could use the dataItem method instead, which will return the model of the selected item. Then you could get the required "value" property. Here is an example, which demonstrates the scenario.

I wish you a great day!

Regards,
Dimiter Madjarov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Madhura
Top achievements
Rank 1
answered on 07 Jul 2014, 11:11 AM
It worked.. Thanks!
Tags
DropDownList
Asked by
Madhura
Top achievements
Rank 1
Answers by
Dimiter Madjarov
Telerik team
Madhura
Top achievements
Rank 1
Share this question
or