Reputation: 3740
I've a Kendo dropdown like below:
KM.ddlModel.bind("loaded", function () {
$("#dvDDL").kendoDropDownList({
dataTextField: "Text",
dataValueField: "Value",
dataSource: KM.ddlModel.cmg
});
Now I would like to set the selected value based on a condition. How can I do it?
Upvotes: 1
Views: 1746
Reputation: 2853
There are many ways you can do this.
At its simplest (a true or false condition), you can do the following:
KM.ddlModel.bind("loaded", function () {
$("#dvDDL").kendoDropDownList({
dataTextField: "Text",
dataValueField: "Value",
dataSource: KM.ddlModel.cmg,
value: (<insert condition>) ? "true" : "false"
});
}
If you condition is more complicated you can do:
function evaluateCondition() {
var returnValue;
// code to decide what the returnValue is
return returnValue;
}
KM.ddlModel.bind("loaded", function () {
var value = evaluateCondition();
$("#dvDDL").kendoDropDownList({
dataTextField: "Text",
dataValueField: "Value",
dataSource: KM.ddlModel.cmg,
value: value
});
}
Or alternatively you can set if after the drop down list is initialised if you have a reference to the drop down list, like:
myDropDownList.value(evaluateCondition());
However you cannot set the value:
configuration property to a function. This is because the value of the value:
property is used by assignment and it is not called like a function.
Upvotes: 2