Search code examples
javascriptkendo-uikendo-dropdown

How can I pass an object from a DataSource to a function from a Kendo DropDownList?


I have a DataSource :

var ds_IMMAT = new kendo.data.DataSource({
    transport : {
        read : {
            url: '<%= Url.Action("GetVehiculesSurSiteAttente", "Entrees_Sorties")%>'
        }
    }
})

GetVehiculesSurSiteAttente is defined in a controller of my ASP project. This is working correctly. I get a list of object.

Then I have a KendoDropDownList :

$("#Cb_Immat_Window").width(135).kendoDropDownList({
    text: "Aucune donnée",
    index: 0,
    dataSource: ds_IMMAT,
    dataTextField: "Immat_Tracteur",
});

I just have to use the name of the variable of the object I want to display with "dataTextField".
My question is the following : How can I pass the entire object that is selected in the DropDownList to a function ? (I want to use the change event of the DropDownList to launch the function)


Solution

  • Inside your change event, use this.dataItem() and you'll have the whole selected object:

    change: function() {
        var dataItem = this.dataItem();
    }
    

    Demo