Skip to content

Commit 8a9794a

Browse files
authored
docs(MultiSelect): Polish basic example (#3071)
1 parent 9ac7f6e commit 8a9794a

File tree

1 file changed

+43
-27
lines changed

1 file changed

+43
-27
lines changed

components/multiselect/overview.md

Lines changed: 43 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,47 +14,63 @@ The <a href="https://www.telerik.com/blazor-ui/multiselect" target="_blank">Blaz
1414

1515
## Creating MultiSelect
1616

17-
1. Use the `TelerikMultiSelect` tag to add the component to your razor page.
17+
1. Add the `TelerikMultiSelect` tag to your razor page.
18+
1. [Bind the `Data` parameter to the collection of objects or strings](slug:multiselect-databind) that you want to appear in the dropdown.
19+
1. Set the `TextField` parameter to point to the object property that holds the user-readable value.
20+
1. Set the `ValueField` parameter to point to the object property that holds the data item value.
21+
1. [Bind the `Value` of the component](slug:get-started-value-vs-data-binding#value-binding) to a collection of the same type as the type defined by the `ValueField` parameter.
22+
1. (optional) Configure additional features like `AutoClose`, `Placeholder`, or `ShowClearButton`.
1823

19-
1. Populate the `Data` property with the collection of items that you want to appear in the dropdown.
20-
21-
1. [Bind the value of the component](slug:get-started-value-vs-data-binding#value-binding) to a collection of the same type as the type defined in the `ValueField` parameter.
22-
23-
1. (Optional) Enable features like placeholder text, clear button, and AutoClose.
24-
25-
>caption MultiSelect two-way value binding, main features, and simple [data binding](slug:multiselect-databind)
24+
>caption Basic Blazor MultiSelect two-way value binding, main features, and simple [data binding](slug:multiselect-databind)
2625
2726
````RAZOR
28-
@* Main features and simple data binding for the suggestions and the Value *@
2927
<TelerikMultiSelect Data="@Countries"
30-
@bind-Value="@Values"
31-
Placeholder="Enter Balkan country, e.g., Bulgaria"
32-
Width="350px" ShowClearButton="true" AutoClose="false">
28+
@bind-Value="@MultiSelectValues"
29+
TextField="@nameof(Country.Name)"
30+
ValueField="@nameof(Country.Id)"
31+
AutoClose="false"
32+
Placeholder="Select Balkan Countries"
33+
ShowClearButton="true">
3334
</TelerikMultiSelect>
34-
@if (Values.Count > 0)
35+
36+
@if (MultiSelectValues.Count > 0)
3537
{
3638
<ul>
37-
@foreach (var item in Values)
39+
@foreach (int countryId in MultiSelectValues)
3840
{
39-
<li>@item</li>
41+
<li><code>Id</code> @countryId, <code>Name</code> @Countries.First(x => x.Id == countryId).Name</li>
4042
}
4143
</ul>
4244
}
4345
@code {
44-
List<string> Countries { get; set; } = new List<string>();
45-
List<string> Values { get; set; } = new List<string>();
46+
private List<Country> Countries { get; set; } = new();
47+
private List<int> MultiSelectValues { get; set; } = new();
48+
4649
protected override void OnInitialized()
4750
{
48-
Countries.Add("Albania");
49-
Countries.Add("Bosnia & Herzegovina");
50-
Countries.Add("Bulgaria");
51-
Countries.Add("Croatia");
52-
Countries.Add("Kosovo");
53-
Countries.Add("North Macedonia");
54-
Countries.Add("Montenegro");
55-
Countries.Add("Serbia");
56-
Countries.Add("Slovenia");
57-
base.OnInitialized();
51+
Countries.Add(new(1, "Albania"));
52+
Countries.Add(new(2, "Bosnia and Herzegovina"));
53+
Countries.Add(new(3, "Bulgaria"));
54+
Countries.Add(new(4, "Croatia"));
55+
Countries.Add(new(5, "Greece"));
56+
Countries.Add(new(6, "Kosovo"));
57+
Countries.Add(new(7, "Montenegro"));
58+
Countries.Add(new(8, "Romania"));
59+
Countries.Add(new(9, "Serbia"));
60+
Countries.Add(new(10, "Slovenia"));
61+
Countries.Add(new(11, "Turkey"));
62+
}
63+
64+
public class Country
65+
{
66+
public int Id { get; set; }
67+
public string Name { get; set; } = string.Empty;
68+
69+
public Country(int id, string name)
70+
{
71+
Id = id;
72+
Name = name;
73+
}
5874
}
5975
}
6076
````

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy