7

I want to pull all data of a kendo dropdown list. I create dropdown with this code:

$("#dropDownList").kendoDropDownList({

    dataTextField: "field",
    autoBind: true,
    dataSource: {
        transport: {
            type: "POST",
            read: {
                url: "http://abc.com",
                contentType: "application/json; charset=utf-8",
                dataType: "json"
            }
        }
    },
    select: onSelect
});

};

Then I tried to pull data with using

var data = $("#dropDownList").data("kendoDropDownList").val();
var values = [];
for (var item in data) {
    values.push(this.item);

}

But it didn't work. Any idea how can I do? Thanks in advance.

kparkin
  • 325
  • 3
  • 7
  • 20

6 Answers6

9

If you want the actual DataItems from the DDL you can get them by Viewing the DataSource:

$("#dropDownList").data("kendoDropDownList").dataSource.view()

You can then also find individual items easily by id if you need to:

$("#dropDownList").data("kendoDropDownList").dataSource.view().find(x=>x.Value === 'ID')
BGTurner
  • 307
  • 3
  • 9
8

Try this it will retrive all values from Kendo dropdown.

var values = [];
    var grid = $("#SampleDropdown").data("kendoDropDownList");

    var ds = grid.dataSource;
    var len = ds._data.length;
    if (len > 0) {
        var i;

        for (i = 0; i < len; i++) {
            var val = ds._data[i].Value;
            values.push(val);
        }
      }
Vijai
  • 2,369
  • 3
  • 25
  • 32
  • Thank you, it didn't work at first but then I remembered we explicitly bound the dataSource using 'Name' and Key' – cfm Sep 12 '16 at 15:11
7

Can you try :

var data = $("#dropDownList").data("kendoDropDownList");
BENARD Patrick
  • 30,363
  • 16
  • 99
  • 105
  • It gets all drop down as an object and I used dataSource property to pull only list data, so thank you for your help. – kparkin Oct 09 '13 at 18:36
3

Try this.

 var values = [];
    var data = $("#dropDownList option").each(function(){
  values.push($(this).val());
  });
sudhansu63
  • 6,025
  • 4
  • 39
  • 52
  • I tried but I dont know why "option" gives an exception here. But I solve my problem, thank you anyway. – kparkin Oct 09 '13 at 18:37
  • not work using KendoComboBox, for example: var data = $("#combo option")?? – Hernaldo Gonzalez Apr 28 '15 at 14:26
  • @HernaldoGonzalez can you make sure that oonly one element with id combobox exitsts in that page ? if there are multiple elements with the same id then you may not get the expected output. – sudhansu63 May 04 '15 at 04:30
0

Simple one liner.

To get all data items:

$("#myDDL").data("kendoCombo").dataSource.data();

To get single property value:

$("#myDDL").data("kendoCombo").dataSource.data()[0].ProductId;

Reference

Shaiju T
  • 6,201
  • 20
  • 104
  • 196
0

$("#dropDownList").data('kendoDropDownList').options.optionList - returns object with values

Andriy Leshchuk
  • 466
  • 3
  • 8