|
| 1 | +--- |
| 2 | +title: Hiding Selected Items in MultiSelect Component |
| 3 | +description: Learn how to hide selected items in the dropdown list of the MultiSelect component. |
| 4 | +type: how-to |
| 5 | +page_title: Hide Selected Items in MultiSelect Dropdown |
| 6 | +slug: hide-selected-items-multiselect |
| 7 | +tags: multiselect,kendo-ui,open-event,filter,selected-items |
| 8 | +res_type: kb |
| 9 | +ticketid: 1686703 |
| 10 | +--- |
| 11 | + |
| 12 | +## Environment |
| 13 | + |
| 14 | +<table> |
| 15 | +<tbody> |
| 16 | +<tr> |
| 17 | +<td>Product</td> |
| 18 | +<td>MultiSelect for Progress® Kendo UI®</td> |
| 19 | +</tr> |
| 20 | +<tr> |
| 21 | +<td>Version</td> |
| 22 | +<td>2025.2.520</td> |
| 23 | +</tr> |
| 24 | +</tbody> |
| 25 | +</table> |
| 26 | + |
| 27 | +## Description |
| 28 | + |
| 29 | +I want to hide the selected items from the dropdown list in the MultiSelect component. Currently, the selected items are highlighted, but I need them to be excluded from the list instead. |
| 30 | + |
| 31 | +This knowledge base article also answers the following questions: |
| 32 | +- How to filter out selected items in Kendo UI MultiSelect? |
| 33 | +- How to remove selected items dynamically in MultiSelect dropdown? |
| 34 | +- How to use the open event to filter items in MultiSelect? |
| 35 | + |
| 36 | +## Solution |
| 37 | + |
| 38 | +To hide selected items from the dropdown list in the [MultiSelect](/controls/multiselect/overview) component, use the [`open`](https://www.telerik.com/kendo-jquery-ui/documentation/api/javascript/ui/multiselect/events/open) event to dynamically filter the dropdown list each time it is shown. The following code demonstrates this approach: |
| 39 | + |
| 40 | +```javascript |
| 41 | +open: function(e) { |
| 42 | + var multiselect = e.sender; |
| 43 | + var selectedValues = multiselect.value(); |
| 44 | + var dataSource = multiselect.dataSource; |
| 45 | + |
| 46 | + // Show all items first |
| 47 | + dataSource.filter(null); |
| 48 | + |
| 49 | + // Then filter out selected items |
| 50 | + dataSource.filter({ |
| 51 | + logic: "and", |
| 52 | + filters: selectedValues.map(function(value) { |
| 53 | + return { |
| 54 | + field: "value", |
| 55 | + operator: "neq", |
| 56 | + value: value |
| 57 | + }; |
| 58 | + }) |
| 59 | + }); |
| 60 | +} |
| 61 | +``` |
| 62 | + |
| 63 | +### Explanation |
| 64 | +1. Attach the `open` event to the MultiSelect component. |
| 65 | +2. Retrieve the selected values using the `value()` method. |
| 66 | +3. Reset the filter by setting it to `null` to ensure all items are initially visible. |
| 67 | +4. Apply a filter to exclude the selected items. This is achieved using the `filter` method with a condition that removes items matching the selected values. |
| 68 | + |
| 69 | +### Example |
| 70 | +A full demonstration can be found in the following Dojo example. |
| 71 | + |
| 72 | +```dojo |
| 73 | +<select id="multiSelect" multiple="multiple"> |
| 74 | +</select> |
| 75 | +<script> |
| 76 | +$("#multiSelect").kendoMultiSelect({ |
| 77 | + dataTextField: "text", |
| 78 | + dataValueField: "value", |
| 79 | + dataSource: [ |
| 80 | + { text: "Item 1", value: 1 }, |
| 81 | + { text: "Item 2", value: 2 }, |
| 82 | + { text: "Item 3", value: 3 }, |
| 83 | + { text: "Item 4", value: 4 } |
| 84 | + ], |
| 85 | + value: [2], // Preselected item |
| 86 | + open: function(e) { |
| 87 | + var multiselect = e.sender; |
| 88 | + var selectedValues = multiselect.value(); |
| 89 | + var dataSource = multiselect.dataSource; |
| 90 | +
|
| 91 | + // Show all items first |
| 92 | + dataSource.filter(null); |
| 93 | +
|
| 94 | + // Then filter out selected items |
| 95 | + dataSource.filter({ |
| 96 | + logic: "and", |
| 97 | + filters: selectedValues.map(function(value) { |
| 98 | + return { |
| 99 | + field: "value", |
| 100 | + operator: "neq", |
| 101 | + value: value |
| 102 | + }; |
| 103 | + }) |
| 104 | + }); |
| 105 | + } |
| 106 | +}); |
| 107 | +</script> |
| 108 | +``` |
| 109 | + |
| 110 | +## See Also |
| 111 | + |
| 112 | +- [MultiSelect Overview Documentation](/controls/multiselect/overview) |
| 113 | +- [Open Event API Reference](/api/javascript/ui/multiselect/events/open) |
| 114 | +- [Filtering in Kendo UI DataSource](/api/javascript/data/datasource/methods/filter) |
0 commit comments