Skip to content

Commit a5f3230

Browse files
Updated multiselect docs for pre-selection (#81)
* chore(multiselect): updated preselect example * chore(multiselect): improve code snippet Co-authored-by: Marin Bratanov <m.bratanov@gmail.com>
1 parent cd8251c commit a5f3230

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed

components/multiselect/overview.md

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ The MultiSelect is a generic component and its type is determined by the type of
8181

8282
* `Enabled` - whether the component is enabled.
8383

84-
* `Filterable` - whether [filtering]({%slug multiselect-filter%}) is enabled for the end user
84+
* `Filterable` - whether [filtering]({%slug multiselect-filter%}) is enabled for the end user
8585
(suggestions will get narrowed down as they type).
8686

8787
* `FilterOperator` - the string operation that will be used for [filtering]({%slug multiselect-filter%}). Defaults to `StartsWith`.
@@ -103,12 +103,12 @@ The MultiSelect is a generic component and its type is determined by the type of
103103
* `TValue` - the type of the value field in the model to which the component is bound. Required if you can't provide `Data` or `Value`. Determines the type of the reference object.
104104

105105
The type of the values can be:
106-
106+
107107
* `number` (such as `int`, `double` and so on)
108108
* `string`
109109
* `Guid`
110110
* `Enum`
111-
111+
112112
* `Value` and `bind-Value`- get/set the value of the component, can be used for binding. Use the `@bind-Value` syntax for two-way binding, for example, to a variable of your own. The `Value` must be a `List<TValue>`.
113113

114114
* `ValueField` - the name of the field from the model that will be used as values in the selection. Defaults to `Value`.
@@ -125,7 +125,12 @@ The MultiSelect is a generic component and its type is determined by the type of
125125
>caption Pre-select items for the user
126126
127127
````CSHTML
128-
@* If the List of items provided to the component contains an item matching the data source, that item will be selected *@
128+
@* You can pre-select an item or set of items only if they exist in the data source. *@
129+
130+
<div>
131+
<TelerikButton OnClick="@SelectHandler">Pre-select countries</TelerikButton>
132+
<TelerikButton OnClick="@ClearSelectionHandler">Clear selection</TelerikButton>
133+
</div>
129134
130135
<TelerikMultiSelect Data="@Countries"
131136
@bind-Value="@Values"
@@ -143,8 +148,24 @@ The MultiSelect is a generic component and its type is determined by the type of
143148
}
144149
145150
@code {
146-
List<string> Countries { get;set; } = new List<string>();
147-
List<string> Values { get;set; } = new List<string>() { "Bulgaria", "Croatia" };
151+
List<string> Countries { get; set; } = new List<string>();
152+
List<string> Values { get; set; } = new List<string>();
153+
154+
void SelectHandler()
155+
{
156+
List<string> PreselectedValues = new List<string>()
157+
{
158+
"Bulgaria", "Croatia"
159+
};
160+
161+
// create a new reference so that the framework can notify the component to update
162+
Values = new List<string>(PreselectedValues);
163+
}
164+
165+
void ClearSelectionHandler()
166+
{
167+
Values = new List<string>();
168+
}
148169
149170
protected override void OnInitialized()
150171
{
@@ -158,6 +179,8 @@ The MultiSelect is a generic component and its type is determined by the type of
158179
Countries.Add("Serbia");
159180
Countries.Add("Slovenia");
160181
182+
// you can also pre-select items here based on data you fetch, not just on a button click
183+
161184
base.OnInitialized();
162185
}
163186
}
@@ -169,4 +192,3 @@ The MultiSelect is a generic component and its type is determined by the type of
169192
* [Live Demo: MultiSelect](https://demos.telerik.com/blazor-ui/multiselect/overview)
170193
* [Live Demo: MultiSelect Validation](https://demos.telerik.com/blazor-ui/multiselect/validation)
171194
* [API Reference](https://docs.telerik.com/blazor-ui/api/Telerik.Blazor.Components.TelerikMultiSelect)
172-

0 commit comments

Comments
 (0)