Is it possible to use knockout to only bind the selected value in an igCombo? I am passing the dropdown list from the server side as the datasource for available options. I have a view model that contains a field with only the "selected" value that will be in the list. I want to use knockout just to bind to the selected value both ways - not the list of valid options in the combo.
Hello Ryan,Thank you for contacting Infragistics Developer Support!Could please share a code sample of what you are trying to achieve? Thank you in advance!
Please see attached. I've taken the combo knockout example from Infragistics web site and added another combo box to the bottom of it. This combo box code originated from server side MVC and I copied into this example. The data source for the available options in the combo is also set on server side, so the list is NOT being filled by knockout. I want to bind the combo "selected" value using knockout. I sort of have this working which you can see in the attached example. What's not working is that initially when I open this page, even though Adam Sandler is selected in the list, it is not defaulted in my newly added combo box. I know it is bound correctly though because it's working after that. Here are steps you can go through.
1. Open the page - you'll see Adam Sandler is "selected" in various controls, but not my combo at the bottom. Why is this?
2. Select another actor and then click back on Adam Sandler. Now you can see Adam Sandler is also selected in my newly added combo box, so I know the binding is working correctly in some instances.
3. Add a new actor named LB. Once you do this, you will again see my newly added combo get filled with "Pounds" (the description for LB).
How can I get the correct selected value in the combo box when the page is opened initially using Knockout?
Thanks!
Hello Ryan,Thank you for the provided information!
Now I understand completely your issue, let me explain what is happening.
You are initializing your combo twice - once using the knockout extension and once using Html MVC helpers and some parts of it are being overridden. In your scenario the both patterns - MVVM and MVC are mixing. So I suggest you to use only one of them, not both. Using the both patterns will make your application code harder to maintain and extend, and even if I can suggest you workaround for your scenario, that approach could lead to possible future issues.
If you want to use the knockout extensions for IgniteUI, you can return your data source from a restful service (most commonly Asp Web Api) and then from the client side you can make ajax request for your data source and bind it to the combo using the knockout extensions. However if your application is not completely MVVM oriented I suggest you to use only MVC Helpers and javascript apis for igCombo and set your selected value for the second combo on selection changed for the first one.
If you have any additional questions, please let me know.
So if I'm understanding you correctly, I take this to mean that knockout binding with igCombo is not really supported if the igCombo is initialized via MVC Helpers? Is that accurate? Or at the very least you wouldn't recommend it?
Hello Ryan,It is supported but I wouldn't recommend it. If you can provide me another sample in Asp MVC this time, with the view, the controller, with some mocked data and model and view model, I could make this work for you.
That's disappointing that you can't easily use the MVC wrapper and still use knockout binding. I have this working now so I don't need any further assistance. Thanks for the help.
Hello Ryan,
Thank you for your cooperation!
I am glad that I have managed to help you.
good job !