Dipon Roy
Dipon Roy

Reputation: 406

Hot to get value/text pairs form kendo dropdown using JavaScript or Jquery

I am using kendo dropdown like:

Html:

<input id="field_timezone" style="width: 275px;" tabindex="4">  

JS:

resultList = $.parseJSON(response.d);   //data via ajax call

$("#field_timezone").kendoDropDownList({
    dataTextField: "TimeZoneDescription",
    dataValueField: "TimeZoneID",
    dataSource: resultList,
    optionLabel: {
        TimeZoneDescription: "Choose",
        TimeZoneID: ""
    }
});

I am trying to find, what value/text pairs for options should be displayed on the dropdown.

I have tried:

alert(JSON.stringify($('#field_timezone').data('kendoDropDownList').dataSource.data()));

Or

alert(JSON.stringify($('#field_timezone').data('kendoDropDownList').dataSource._data));

gives the list used for datasource, but it's missing the "Choose" option, and no option to find out which fields are been used for value or text.

Upvotes: 1

Views: 1424

Answers (1)

DontVoteMeDown
DontVoteMeDown

Reputation: 21465

And its right. DataSource isn't suposed to have the optionLabel data, because it isn't data, actually. You can reach an option property with this:

$('#field_timezone').data('kendoDropDownList').options.optionLabel

To get the option label directly, try this:

var ddl = $('#field_timezone').data('kendoDropDownList');
var option = ddl.options.optionLabel[ddl.options.dataTextField];

Upvotes: 1

Related Questions