Kendo ui select index / text specs on first boot

The problem I am facing is that during the first page load I want to read the value from cookies, if it is found, I want to change the theme that was saved in the cookie. not only want to change them, but I also want to select this element in the combo box so that it synchronizes with the ones that were applied.

How can I select a specific item while loading the start page, when I create a drop down box?

$(document).ready(function () {

   var initialized = false;
        // theme chooser drop-down
        var cmb=$(".themeChooser").kendoDropDownList({
            dataSource: [
                    { text: "Default" },
                    { text: "BlueOpal" },
                    { text: "Bootstrap" },
                    { text: "Silver" },
                    { text: "Uniform" },
                    { text: "Metro" },
                    { text: "Black" },
                    { text: "MetroBlack" },
                    { text: "HighContrast" },
                    { text: "Moonlight" }
            ],
            dataTextField: "text",
            dataValueField: "value",
            change: function (e) {

                $.cookie('selectedTheme', theme);
                changeTheme(theme);

            }
        });

        theme = ($.cookie('selectedTheme') || "default").toLowerCase();
        //Not sure how to trigger the select of combobox
        cmb.value(theme);  // no effect                       
});
+4
source share
2 answers

Get a dropdown link

var dropdownlist = $("#Instrument").data("kendoDropDownList");

If you know an index you can use:

// selects by index
dropdownlist.select(1);

, :

// selects item if its text is equal to "test" using predicate function
dropdownlist.select(function(dataItem) {
    return dataItem.symbol === "test";
});

http://jsfiddle.net/OnaBai/mRmNJ/

+8

.

, :

//trigger the select of combobox 
cmb.select(function(dataItem) {
    return dataItem.text === theme;
});

value

value = ($.cookie('selectedTheme') || "default").toLowerCase(),
+1

All Articles