You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: Learn how to pre-select items for the user by exploring a practical example.
5
5
slug: multiselect-pre-select-items
6
6
tags: telerik,blazor,multiselect,pre-select
@@ -9,59 +9,82 @@ position: 8
9
9
---
10
10
11
11
12
-
# Pre-Selecting Items
12
+
# Pre-Select MultiSelect Items
13
13
14
-
This article provides an example that demonstrates how to pre-select items for the end-user. The described approach allows you to pre-select a single item or a set of items if they exist in the data source.
14
+
This article provides an example that shows how to pre-select MultiSelect items for the user. The approach allows you to pre-select a single item or a set of items if they exist in the data source.
15
+
16
+
On page load, the MultiSelect will render the selected items in the order in which these items appear in the `Data` collection. To preserve the order of the initially selected items, [sort the data to match the selected items order]({%slug multiselect-kb-selected-items-order%}).
17
+
18
+
>caption Pre-select MultiSelect items for the user
15
19
16
-
>caption Pre-select items for the user
17
20
````CSHTML
18
-
@* You can pre-select an item or set of items only if they exist in the data source. *@
title: MultiSelect Reorders and Sorts Selected Items
3
+
description: How to disable automatic sorting of Blazor MultiSelect selected items? How to override any reordering of selected MultiSelect values?
4
+
type: troubleshooting
5
+
page_title: Blazor MultiSelect Reorders and Sorts Selected Items
6
+
slug: multiselect-kb-selected-items-order
7
+
position:
8
+
tags: multiselect
9
+
ticketid: 1540543, 1557872
10
+
res_type: kb
11
+
---
12
+
13
+
## Environment
14
+
15
+
<table>
16
+
<tbody>
17
+
<tr>
18
+
<td>Product</td>
19
+
<td>MultiSelect for Blazor</td>
20
+
</tr>
21
+
</tbody>
22
+
</table>
23
+
24
+
25
+
## Description
26
+
27
+
The MultiSelect selected items order changes. The component sorts the list of numbers that represent the selected values. This causes the selected items (tags, chips) to show up in the wrong order. How to override this behavior?
28
+
29
+
The MultiSelect reorders selected items alphabetically. The items in the initial `Value` collection are in the correct order, but the MultiSelect sorts them. Is there any way to preserve selection order and disable automatic self sorting?
30
+
31
+
32
+
## Cause\Possible Cause(s)
33
+
34
+
The selected items' order in the MultiSelect `Value` matches the order of these items in the `Data`. This applies to initial page load and when the MultiSelect `Value` changes programmatically.
35
+
36
+
The MultiSelect creates a collection of its selected items internally, based on `Value` and `Data`. Then, the component uses this internal collection for rendering. That's why the rendered selected items always match the order of the data items. This behavior is related to performance.
37
+
38
+
39
+
## Solution
40
+
41
+
Sort the MultiSelect `Data`, according to the selected items' order in `Value`. For example, move the selected items to the beginning of the `Data` collection.
42
+
43
+
Optionally, use the [MultiSelect `OnChange` or `ValueChanged` events]({%slug multiselect-events%}) to reorder the MultiSelect `Data` every time when users select or unselect items. [`Rebind()`]({%slug common-features-data-binding-overview%}#refresh-data) the MultiSelect afterwards to re-render the dropdown.
44
+
45
+
>caption Reorder MultiSelect Data to match the selected items order in Value
0 commit comments