Search code examples
jsonkendo-uikendo-dropdown

Grabbing Certain Values in Kendo Dropdown list


Hello I am very new to Kendo UI and I am having issues getting certain value which is sent back from my controller in a Json format.

Json that is returned

enter image description here

My drop down list is binded to a view model

 var viewmodel = kendo.observable({
    region: "",
    id : "",
    } );

$("#engagementType").kendoDropDownList({
    optionLabel: "Select Region",
    dataTextField: "OfficeGroup",
    dataValueField: "OfficeGroupID",
    dataSource: {
        transport: {
            read: {
                url: "home/GetRegionList",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                method: "POST",
            }
        }
    },

    select: function(e){
        viewmodel.region = e.item[0].innerText;
        viewmodel.id = e.?????????????????? <<< cannot find the office group id
    }
});

Currently with the selected function I am able to get the office group names, however I when I am trying to get the Office group Id I am not seeing it coming in on "e" which is in my selected function. Should I get the office Id another way?


Solution

  • Kendo UI DropDownList does have functions value() and text(). Value function returns currently selected item dataValueField property value. Text function returns dataTextField property value.

    On select function you can get values like this

    select: function(e) {
    
        // selected value
        console.log(this.value());
    
        // selected text
        console.log(this.text());
    
        // selected item (ObservableObject)
        var dataItem = this.dataItem(e.item);
        console.log(dataItem);
    }