With the new kendo multiselect how would I add options to the list and make them selected?
For instance if I have a dropdown containing: 1,2,3 and I wanted to add 4 and 5 how do I do that? Do I have to destroy the multiselect, add the options and then reinit the multiselect?
Given the following
multiselect
definition:You can use:
For getting the list of values.
And for setting the value to South America (element with
value
5) and "Asia" (element withvalue
3) use:If you want to add values to whatever it has then you need a little trick:
Warning: If values 4 and 5 were already selected you will end up having them duplicated.
Just want to add some information about how to actually add new values to the multi-select.
As OnaBai points out, the code to add an item to the multi-select is
given the .cshtml
In order to add an item as entered in the multi-select hook the change event for the text input. Since this isn't uniquely identified, I use XPath to get the
<input>
element. This is hooked indocument.ready
(in .cshtml, so escape@
):