I've been working with the MultiSelect widget for a while now but this has led to a few questions....
Is there anyway to add or remove selections programmatically? I've implemented the following code in the select event but having tried lots of different methods, as suggested in the forums, I cannot get this to work (e.g. clearing the datasource filter and setting value seems to be the most popular). My multiselect is remote bound. My onSelect event is shown below.
Is there a better way of getting the dataItem rather than how I'm doing it in the first line?
6 Answers, 1 is accepted
You can check out the following how-to article from our documentation that shows selecting/deselecting all items programmatically and adjust it to select/deselect specific items only:
Let us know if you need further assistance.
Thanks for your response but I'd already looked at that How-To but it seems to work in a different way - all items are local and so already exist in the DataSource. I'm trying to do this using a service.
When I add an item into the selection, the server is called but the filter is blank and so since my service returns the top 100 items (and the selected item is not contained in this list) it doesn't get included in the data source. Having said all of that, I already have an instance of the item I would like to add, so having it going back to the server is not that important.
Since I have an instance of the item to add, manually adding into the data source and pushing its ID into the selection doesn't always seem to work. Here's some sample code which isn't exactly the same as I'm trying to do but is a good start...
The described issue is caused by the following known limitation of server filtering in the context of the Kendo UI dropdown widgets:
To be able to add items that are not in the current page of data to the MultiSelect's value, you should utilize the Virtualization functionality of the widget, as described in the following documentation article:
You can also check out our MultiSelect Virtualization demo for a sample implementation of the required configuration and valueMapper:
I hope this helps, but if I am missing something, please describe the scenario, and the desired functionality in further details, so we can provide further, and more to-the-point suggestions.
I have a related problem with this.
I have a successfully virtualized MultiSelect working.
As a user types in to the field searching for a specific record, they find there isn't one. Through a separate button on the page, they execute a function to add to the list of options. This triggers an Ajax call that updates the lookup table adding a new record, and it returns the key for that record. Upon success, it updates the value of the MultiSelect to add the newly created record to the list of selected records.
The problem I'm running into is that the server's mapper function is returning (for example) 1267 for the index into the dataset where the newly created record is found. Since the dataset is sorted alphabetically, this is not going to be the last record. When the control reads the return from the mapper, it says, "Hey, I've already retrieved the record at position 1267, and it displays it without going back to the server to update the list of options. The problem is that this is what WAS at 1267 (and is now at 1268) is being selected - sometimes.
I had the following records in my database. ..., test, theory, ... I typed test into the MultiSelect, and saw that (of course) test1 wasn't in there. So, I clicked on the button I added, entered my new value (test1) and saved. The MultiSelect successfully selected test1. I then clicked on the button again, and I entered another new value (test2) and saved. The MultiSelect showed test1 and theory. If I clicked on the MultiSelect to view the items, I indeed saw test1 followed by theory. However, if I typed "test" in for searching and the virtualization kicked in and started talking to the server, I saw test1 and test2. Now, if I cleared my search text, I saw ..., test, test1, test2, theory, ...
I think what I'm looking for is a way to manually clear or reset the data already retrieved for pages of selections the MultiSelect has seen. When I successfully add a new lookup value, I want to call a method that tells the MultiSelect, "Hey, your cached data isn't quite accurate anymore. You're going to need to go to the server to get current selections.
Is there a way to do this?
Unfortunately, any manual data operations, such as add, filter, remove, page, read, etc. can lead to undesired behavior, and is not supported in scenarios with virtualization (this applies to all Dropdown widgets that share common virtualization functionality):
You can try creating a new DataSource after adding the item to the remote service via the described AJAX call, and use the setDataSource() method to set it to the MultiSelect, but I cannot guarantee this would yield the desired effect in the specific scenario.
In general, non-supported scenarios and/or feature customization fall outside the scope of our support service, but if you send us an isolated runnable project, similar to the ones in our online demos, we can take a look, and try to provide a relevant suggestion, if one is available, and the desired functionality can be achieved with our API.
Telerik by Progress