Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kendo combobox bound to odata not looking up text for value set

Tags:

kendo-ui

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?

like image 775
James Hancock Avatar asked Oct 05 '22 19:10

James Hancock


1 Answers

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/.

like image 57
OnaBai Avatar answered Oct 10 '22 02:10

OnaBai