Retrieve selected item in a KendoComboBox

1 Answer 2756 Views
ComboBox
Maurizio
Top achievements
Rank 1
Iron
Maurizio asked on 20 Sep 2018, 08:34 PM

I have this code on my jhtml page:

$("#myselect").kendoComboBox({
                        dataTextField: "Name",
                        dataValueField: "Id",
                        filter: "contains",
                        autoBind: false,
                        minLength: 3,
                        dataSource: {
                            serverFiltering: true,
                            type: "json",
                            transport: {
                                read: {
                                    url: "/controller/retrivedata",
                                    contentType: "application/json;",
                                    dataType: "json",
                                    data: function () {
                                        return {
                                            CustomId: data.MyCustomIdValue
                                        }
                                    }
                                }
                            }
                        },
                        select: function (e) {
                            if (e.dataItem) {
                                var dataItem = e.dataItem;
                                alert(selectedItem.Id);
                                alert(selectedItem.Name);
                                data.OtherComboId = parseInt(selectedItem.Id);
                                $('#otherCombo').data('kendoComboBox').dataSource.read();
                            }
                        }
                    });

 

The combo box load data correctly but on the select event I can not get the select object. I need the data value.

e.dataItem is undefined.

e.item contain the LI element but I never have found the value (onli the text)

How I can read the datavalue?

LSo

1 Answer, 1 is accepted

Sort by
0
Plamen
Telerik team
answered on 24 Sep 2018, 05:13 AM
Hello,

I have tested the scenario with a similar configuration to the one you shared and the dataItem was present at my side with the latest version of the widgets:
$("#products").kendoComboBox({
                   placeholder: "Select product",
                   dataTextField: "ProductName",
                   dataValueField: "ProductID",
                   filter: "contains",
                   autoBind: false,
                   minLength: 3,
                   select: function (e) {
                       console.log(e.dataItem);
                   },
                   dataSource: {
                       type: "odata",
                       serverFiltering: true,
                       transport: {
                           read: {
                               url: "https://demos.telerik.com/kendo-ui/service/Northwind.svc/Products",
                           }
                       }
                   }
               });

Yet if you still can't get it you could use the code below to evaluate it from e.item:
e.sender.dataItem(e.item)


Regards,
Plamen
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
ComboBox
Asked by
Maurizio
Top achievements
Rank 1
Iron
Answers by
Plamen
Telerik team
Share this question
or