programmatically select a value in dropdown

1 Answer 6525 Views
DropDownList
Maksim
Top achievements
Rank 1
Maksim asked on 06 Jun 2013, 01:42 PM
Hi

I want to store selected item state. I can't trigger 'select' event properly.
    $('#groups').kendoDropDownList({
        dataSource: [
            { text: "No group", value: "none" },
            { text: "By type", value: "type_label" },
            { text: "By route", value: "route_label" },
            { text: "By status", value: "status_label" }
        ],
        dataTextField: "text",
        dataValueField: "value",
        select: function(e){
            var selectedDataItem = this.dataItem(e.item.index());
        set_global_setting ("group_state", dataItem.value);
// ... code which depends on selectedDataItem and works this.dataSource
        }
    }).data("kendoDropDownList").select(function(dataItem){
        return dataItem.value === get_global_setting("group_state");
    });
 
    var groups_dropdown = $('#groups').data("kendoDropDownList");
    groups_dropdown.trigger("select", {item : groups_dropdown.dataItem()}); // does not work since 'select' event expects 'e.item' as 'li'
When user changes selected value 'e.item' in 'select' event is a 'li'.
When I change selected value programmaticlly I should specify next selected item not as dataItem but as 'li'.
How can I do this?
Maybe I should somehow change 'selectedDataItem' definition in 'select' event?

1 Answer, 1 is accepted

Sort by
0
Dimiter Madjarov
Telerik team
answered on 07 Jun 2013, 01:36 PM
Hello Maksim,


You don't have to trigger the select event manually. The value of the DropDownList could be set with the select method of the API, and also with the value method. The first one accepts a list item, index or a boolean function as a parameter, and the second one accepts the value field property. Both are demonstrated in the DropDownList API demo

 

Regards,
Dimiter Madjarov
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
DropDownList
Asked by
Maksim
Top achievements
Rank 1
Answers by
Dimiter Madjarov
Telerik team
Share this question
or