
The problem I see is that if I change the value in the model the DropDownList does not display the correct value. I think that if I have the modelview bond to the input value that changing the value in the model would cause the DropDownList to select the right value as well and display it as the selected item.
24 Answers, 1 is accepted
Could you please paste here your code? Does it work if you don't use the DropDownList extension over your input element?
All the best,Atanas Korchev
the Telerik team

I am now using the MVC DropDownListFor() which generates an HTML select element and I pass in the knockout attributes required in the htmlAttributes parameter. From there it is all downhill with Kendo, knockout bindings and jQuery manipulation.

Example:
I have this at the top of the page:
<script type="text/javascript">
(function ($, undefined) {
$(document).ready(function () {
var serverModel = @Html.Interpret(Model); //this is my way of getting a server side mvc viewmodel to convert down to a client view model
var viewModel = work.viewModel;
viewModel.initialize(serverModel);
viewModel.bind();
$('input[type=date]').kendoDatePicker({format: 'MM/dd/yyyy'});
$('select').kendoComboBox();
$('#tabs').tabs();
});
})(jQuery);
</script>
<select data-bind="options: stateLookup, optionsText: 'Name', optionsValue: 'Id', optionsCaption: 'select one ...', value: model.Location.StateId, valueUpdate: 'change, blur'" id="Work_WorkRequestLocation_StateId" name="Work.WorkRequestLocation.StateId"></select>
<select data-bind="options: parishLookup, optionsText: 'Name', optionsValue: 'Name', optionsCaption: 'select one ...', value: model.Location.Parish, valueUpdate: 'change, blur'"id="Work_WorkRequestLocation_Parish" name="Work.WorkRequestLocation.Parish"></select>
2 Drop Downs above, with State and Parish using KnockoutJS to bind them to properties stateLookup and parishLookup respectively on the viewModel. In my view model I have an event bound to dynamically and remotely change the Parish if the state changes:
//State/Parish Lookup Select Event
$(options.stateSelector).change(function (e) {
var stateId = $(this).val();
var url = options.baseLookupUrl('GetParishes');
$.ajax({
url: url,
data: { stateId: stateId },
type: 'post',
success: function (data) {
viewModel.parishLookup.removeAll();
for (var i = 0; i < data.length - 1; ++i) {
viewModel.parishLookup.push(data[i]);
}
}
});
});
As you can see I am manipulating the parishLookup observableArray from knockout and if I do not use Kendo UI Combobox this works perfectly. However, if I use Kendo UI, and I manipulate the observable collection, Kendo Combobox doesnt change the values. My guess is that KnockoutJS is changing the now hidden Select and the Kendo ComboBox (the div setup above it) does not respect it. KnockoutJS has bound the observableArray to the Select Box. Somehow there need to be a link between when something changes in the Select Box. Somehow you will need to subscribe to the event of that and make similar changes in your Dropdown/ComboBox.
In this way a user can turn all of there select boxes to Kendo ComboBoxes/DropDowns and work with the standard Select box (through javascript) and your Kendo UI works on its own because it is subscribed to that Select and is monitoring it. Otherwise, there will need to be an additional plugin that you add for Kendo UI that allows these UI controls to work appropriately with KnockoutJS, since you would not want to add those fixes to work with it in the common kendo.all.min.js.
Thoughts? To work fully with KnockoutJS, something more needs to be done. I can only see KnockoutJS getting more and more popular, since Silverlight developers are looking for a way to utilize Html 5 and still get the rich binding they had with WPF/Silverlight. KnockoutJS is the answer for them, and they will be looking to Telerik for an easy way to do there rich controls, but not get in the way like the MVC3 controls do.
Yes, you are right. KO currently updates the underlying select and the combobox does not know of this. Indeed more code is required to handle changes in the KO observable array. We will probably implement this in a future release of Kendo UI. Thanks for bringing this up!
Regards,Atanas Korchev
the Telerik team

If not, then there will need to be alot of additionaly plugins to work with peoples favorite MVVM/MVC client side stuff. It might be simpler to just roll your own. Of course, the closer to Silverlight and simpler it is (i.e. KnockoutJS) type binding the better for me, but there is room for improvement. Or you could just partner with KnockoutJS like they do with jQuery Templates, and not re-create the wheel. I was just wondering your thoughts and direction. I have alot of Html5 applications planned for 2012, and it would be critical to know your direction on this, as this would be necessary for us to have a simple binding mechanism.
We have been thinking to implement such a plugin but this is still in the research phase so I cannot commit with any definitive response.
The short-term solution would be a bit better KO support (or as you call it partnering). I think the only thing missing now is listening to changes in observable arrays.
Atanas Korchev
the Telerik team

I created a Kendo UI Knockout Custom binding that utilize the Kendo ComboBox: Custom Kendo ComboBox Binding (jsFiddle)
As you can see it works well, binds the datasource to the kendo combobox, respects the observable array changes, ignores invalid changes, and sets the observable selected item back and forth.
I basically took my jquery autocomplete version and changed it to work with ComboBox. Here is the dropdown knockout custom binding version.
Here is the Date Picker Custom Knockout Binding, this allows you to bind to a Date object in your viewModel without having to worry about converting to and from a string and respects the observable property from the ViewModel. <
Hopefully we can convince Telerik Devs to create a custom knockout binding version for all the Kendo UI Controls. This would make using kendo ui controls with knockout trivial and extremely simple.
.jpg)
I would love to see an effort to work better with Knockout ... because if we have to choose, we all lose.
-- JP
Unfortunately as can be seen from the jsFiddle code snippets integrating with KO is not a walk in the park. It requires quite a lot of knowledge how KO works internally and some code to make things actually work I've asked for some support before and I got the same answer - we need deeper integration such as custom bindings etc. We just can't spare the required resources now having in mind that we are working on our own Kendo MVVM implementation.
In the future we will provide some Knockout integration as a separate open source project (probably hosted on github).
Atanas Korchev
the Telerik team
.jpg)

What I dont get, is why dont you make a api datasource layer that allows a user to use there own MVVM plugin (or just use Knockout) since it works so incredibly well. Why do you have to re-invent the wheel when there is already something out there that is very popular and already known how to use?
If you come out with your own MVVM tool, then devs will have to utilize your MVVM Plugin with another, like Knockout, and it would be overkill. It will be only for the sake of utilizing your Html 5 Controls. Which, if you are going to make the claim that they are Html 5 Controls, they should be simple and unobtrusive to utilize with existing common plugins. They shouldn't get in the way or make you have to switch what you have been using for over 3 years just to use the controls.
I hope you guys look deeper in Knockout integration, at least from the aspect of creating a Knockout Datasource (since all controls work off of a datasource) that can 2 way bind to a ko.observable object and a ko.observableArray object. I am not looking forward to finding creative ways to try to keep all of my vast amount of plugin helpers etc with Knockout, and having to fudge in another MVVM library just to get it to respect my 2-way bindings in knockout.
Up to your questions:
"What I dont get, is why dont you make a api datasource layer that allows a user to use there own MVVM plugin (or just use Knockout) since it works so incredibly well"
We have not yet created a KO aware DataSource because we have not yet allocated any resources for this task. This is the same as asking why feature X is not implemented. There is no simple answer - we have our priorities and can't just implement all feature requests instantly. We have established the tasks for the next release long ago and there is no way change priorities now. I believe any single software vendor works this way so this is not something new. As I said in my previous reply a KO aware DataSource will be implemented *after* our Q1 2012 release.
"Why do you have to re-invent the wheel when there is already something out there that is very popular and already known how to use?"
I don't really understand the question. We believe that there is room for improvement in existing libraries and we want to provide built-in integration with the rest of Kendo UI. As you have seen KO integration is not an easy task at all. By the way I haven't found *any* UI plugin which plays nicely with KO. I have personally tried various jQuery based plugins and none of them works with KO observables. Feel free to correct me if you have stumbled upon.
"If you come out with your own MVVM tool, then devs will have to utilize your MVVM Plugin with another, like Knockout, and it would be overkill "
Our MVVM tool will be a replacement of KnockoutJS. It will work with Kendo UI widgets and "vanilla" HTML elements. Of course we won't match every single feature of KO as this is not our goal.
"They shouldn't get in the way or make you have to switch what you have been using for over 3 years just to use the controls."
Have you used any jQuery based UI plugin successfully with KnockoutJS? If yes could you let me know which one that is? If there is such a plugin perhaps there is an easier way to integrate with KO.
Here is a summary of the KnockoutJS/Kendo integration:
- The current demo has a bug caused by the DropDownList itself. This bug has been fixed already and the demo will work as expected in our next release (Q3 2011 SP1).
- No Kendo UI widgets will be updated if an observableArray changes. The underlying element will be updated (the original <select> from which a DropDownList is created). Since it is not possible to get the observable to which an element is bound we need to implement a KnockoutJS-aware datasource in order to support change notifications. Since we don't want to include 3rd party integration code in the Kendo UI codebase we would release this DataSource as an open source project on github. Development will start post Q1 2012 (which is due in late March).
- We are currently working on our own MVVM implementation which will provide built-in integration with all Kendo UI widgets.
Regards,
Atanas Korchev
the Telerik team
There are a few concerns I have about this.
First, after seeing a great JSFiddle of a KO custom binding for the KendoUI combo box, it's apparent it will be a lot of work. But, if it works as well as Corey's example, it would be well worth the effort.
Second, as Atanas mentioned, the Kendo team is working on their own MVVM implementation. I guess this should be evaluated once delivered in some form to determine if a custom bindings library even makes sense.
Lastly, I suspect there will be a number of changes to the KendoUI widgets and data-viz items in the coming months. As with any new offering, it could be difficult to keep up with the pace of the Kendo team's releases to make sure a KO custom bindings project remain in lock-step.
Thoughts?

Thanks for the comment.
I have actually created several Kendo UI Knockout Custom Bindings. I only stopped because I tackled the Grid and realized that I could not get past it without modifying or extending the Kendo Data Source. That was the road block I hit. I need the Data Source to be able to have more events than it has so that I can tie into it to report back changes in the Grid to the Knockout Observable Array. With more Events on the Knockout Data Source i could complete it.
Here are my custom Knockout Bindings so far: (you are welcome to change up and help if you are interested):
ComboBox - Custom Binding
Dropdown - Custom Binding
Numeric Text - Custom Binding
DatePicker - Custom Binding
ALPHA - Grid - Custom Binding (need more events for Kendo UI DataSource - it can do bare basics)
AutoComplete - jQuery UI - Custom Binding
Date in a Span (Readonly view of Date Fields) - Custom Binding

I did not think of managing it all that mapping between the Kendo DataSource. Great idea.
Thanks for sharing the other JSFiddles links as well. I'm really just beginning to understand the KO custom binding architecture and your code samples really help in that respect.
I have a little experience in Backbone, any idea if this would be any easier as a Backbone plugin or do you think the Kendo DataSource would still be the limiting factor?
BTW, I don't want to come across as bad mouthing the KendoUI product(s). I am just very excited about what they have provided and want it all to work right now. :) I am sure 12 months from this this thread will be moot.
.jpg)
Kendo team ... I realize you have a vision of where you want the product to head, but integration should be a larger focus. Whether you can do it better yourselves or not, the bottom line is that many developers already use many libraries.

John... I agree. I think there are many people watching this and are concerned about proper two way data binding support in their visually nice looking control stack (or lack of I should say).
Appreciate such libraries are non-trivial, taken time to build, necessary and in the case of as you point out Knockout, has gained significant momentum.


You will definitely get those Web Devs that haven't settled on a MVVM JavaScript framework yet, but you can appeal to both groups by opening up your kendo datasource to be alot more friendly to other MVVM libraries.
Those that have settled on a known MVVM library, you will leave them looking for the html 5 control suite that does what they want it to do without being intrusive, and they will leave Kendo when it comes out. This is not the model you want to position your control suite to become the defacto controls.
You really need to talk to outside Web Developers before you take on such a one minded approach, get there feel for what is right, they are your audience you are selling to.
Telerik is known for listening to their audience, dont stop now.
Bottom line is, we wouldn't be arguing with your strategy if we weren't fans of Telerik and Kendo. This is a complement to your team, but you must hear your fans out.

I have used backbone to play around with before I started using Knockout, and it just does too much for me and you have alot of setup you need to do. Knockout does one role, and it does it well. I am a big fan of XAML binding, and it is the one JavaScript MVVM library that is the closest to this approach. I like handling my own View Model object and using Knockout to do the binding for me, and having my own navigation library, etc.
As for this binding being easier on backbone, no, it would essentially be the same problem. The main problem in terms of the Grid for me is that there is no events on the Kendo Datasource to tell me when something has changed or the Grid was effected some how, without that, I cant tell the MVVM Library it has changed and change the underlining javascript array. I have no glue from Kendo to adapt to the MVVM Library, its only one way I can listen. So it will end up being only one way binding until they add a significant amount of events on the datasource, as well as useful parameters on those events to tell what has changed.

Did you check this blog post? I think that everything we had to say is nicely summarized there.
Regards,Atanas Korchev
the Telerik team

I am working as a java developer. I am developing a project in jsp. i want to get data from the data base. for that i need three values to filter the data. so i need to get the values from the user first one field is a drop down list the second one also drop down list but the third one is a text box or drop down list but this is depend on the second drop down list value. how shall i do that. the third input field is based on second one how could i do this pls help me