Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to retrieve all data of a kendo ui dropdown list?

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.

like image 464
kparkin Avatar asked Oct 08 '13 14:10

kparkin


4 Answers

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);
        }
      }
like image 106
Vijai Avatar answered Nov 15 '22 22:11

Vijai


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')
like image 41
BGTurner Avatar answered Nov 15 '22 22:11

BGTurner


Can you try :

var data = $("#dropDownList").data("kendoDropDownList");
like image 44
BENARD Patrick Avatar answered Nov 16 '22 00:11

BENARD Patrick


Try this.

 var values = [];
    var data = $("#dropDownList option").each(function(){
  values.push($(this).val());
  });
like image 23
sudhAnsu63 Avatar answered Nov 16 '22 00:11

sudhAnsu63