How to get all kendo ui dropdown list data?

I want to get all the data from the kendo drop-down list. I am creating a dropdown using 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 extract data using

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

But that did not work. Any idea how I can do this? Thanks in advance.

+6
source share
6 answers

Can you try:

 var data = $("#dropDownList").data("kendoDropDownList"); 
+7
source

Try this, it will select all the values ​​from the Kendo drop-down list.

 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); } } 
+7
source

Try it.

  var values = []; var data = $("#dropDownList option").each(function(){ values.push($(this).val()); }); 
+3
source

If you want the actual DataItems from DDL, you can get them by looking at the data source:

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

Then you can also easily find individual elements by identifier if you need:

 $("#dropDownList").data("kendoDropDownList").dataSource.view().find(x=>x.Value === 'ID') 
+3
source

Simple one liner.

To get all data items:

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

To get one property value:

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

Link

0
source

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

0
source

Source: https://habr.com/ru/post/955500/


All Articles