I have a standard kendo web combo box that is bound to an odata data source. It looks up fine if you type into it and gets the right text and value.
However if you have it bound, and you set the .value() property in code, the text does not get looked up for the value that was set. (pretty standard behavior if you're loading existing data)
I would have assumed that it would have gone to the server and looked up by the dataValueField property for the exact value and returned the item specifically and set the text.
How do I go about making it do this?
Lets have the following ComboBox
:
var combobox = $("#combobox").kendoComboBox({
dataTextField : "ProductName",
dataValueField: "ProductID",
dataSource : {
type : "odata",
transport: {
read: "http://demos.kendoui.com/service/Northwind.svc/Products"
}
}
}).data("kendoComboBox");
(You can use it yourself since it refers to a service available in Kendo UI servers).
Then you can use the following pieces of code for setting the value
or the text
(whatever you prefer).
// Set value of the ComboBox using dataValueField (ProductId)
combobox.value(4);
// Set value of the ComboBox using dataTextField (ProductName)
combobox.text("Chef Anton's Cajun Seasoning");
And for reading you should use:
alert("Current text/value: " + combobox.text() + "/" + combobox.value());
Both methods work fine as you can check in here http://jsfiddle.net/OnaBai/64gXE/.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With