|
1 | 1 | ---
|
2 | 2 | title: Filter
|
3 |
| -page_title: DropDown List for Blazor | Templates |
4 |
| -description: Templates in the DropdownList for Blazor |
| 3 | +page_title: ComboBox for Blazor | Filter |
| 4 | +description: Filtering in the ComboBox for Blazor |
5 | 5 | slug: components/combobox/filter
|
6 |
| -tags: telerik,blazor,dropdownlist,dropdown,list,templates |
| 6 | +tags: telerik,blazor,combo,combobox,filter |
7 | 7 | published: True
|
8 | 8 | position: 1
|
9 | 9 | ---
|
10 | 10 |
|
11 |
| -# DropDownList Filter |
| 11 | +# ComboBox Filter |
12 | 12 |
|
13 |
| -The DropDownList component allows you to change what is rendered in its items, body, header and footer through templates. |
| 13 | +The ComboBox component allows the user to filter the available items by their text, so they can find the one they need faster. |
14 | 14 |
|
15 |
| -The examples below show how to use inner tags to set the templates. You can also do this through [RenderFragment](https://blazor.net/api/Microsoft.AspNetCore.Blazor.RenderFragment.html) objects that you can pass to the properties of the DropDownList in its main tag. |
| 15 | +To enable filtering, set the `Filterable` parameter to `true`. |
16 | 16 |
|
17 |
| -List of the available templates: |
| 17 | +The filter operator is `contains`, it looks in the `TextField`, and filtering is reset when the dropdown closes. |
18 | 18 |
|
19 |
| -* [Value Template](#value-template) |
20 |
| -* [Item Template](#item-template) |
21 |
| -* [Header](#header) |
22 |
| -* [Footer](#footer) |
23 |
| - |
24 |
| - |
25 |
| -## Value Template |
26 |
| - |
27 |
| -The Value template determines how the selected item renders in the main element of the dropdown list that is always visible. By default, the text from the model is rendered. |
28 |
| - |
29 |
| ->caption Value Template Example |
30 |
| -
|
31 |
| -````CSHTML |
32 |
| -Change what renders in the main element |
33 |
| -
|
34 |
| -<TelerikDropDownList Data="@myDdlData" TextField="MyTextField" ValueField="MyValueField" Value="1"> |
35 |
| - <ValueTemplate> |
36 |
| - <strong>@((context as MyDdlModel).ExtraField)</strong> |
37 |
| - </ValueTemplate> |
38 |
| -</TelerikDropDownList> |
39 |
| -
|
40 |
| -
|
41 |
| -@code { |
42 |
| - public class MyDdlModel |
43 |
| - { |
44 |
| - public int MyValueField { get; set; } |
45 |
| - public string MyTextField { get; set; } |
46 |
| - public string ExtraField { get; set; } |
47 |
| - } |
48 |
| -
|
49 |
| - IEnumerable<MyDdlModel> myDdlData = Enumerable.Range(1, 20).Select(x => |
50 |
| - new MyDdlModel |
51 |
| - { |
52 |
| - MyTextField = "item " + x, |
53 |
| - MyValueField = x, |
54 |
| - ExtraField = "more item info " + x |
55 |
| - } |
56 |
| - ); |
57 |
| -} |
58 |
| -```` |
59 |
| - |
60 |
| ->caption The result from the code snippet above |
61 |
| -
|
62 |
| - |
63 |
| - |
64 |
| -## Item Template |
65 |
| - |
66 |
| -The Item template determines how the individual items are rendered in the dropdown element of the component. By default, the text from the model is rendered. |
67 |
| - |
68 |
| ->caption Item Template Example |
69 |
| -
|
70 |
| -````CSHTML |
71 |
| -Define what renders for the items in the dropdown |
72 |
| -
|
73 |
| -<TelerikDropDownList Data="@myDdlData" TextField="MyTextField" ValueField="MyValueField" Value="1"> |
74 |
| - <ItemTemplate> |
75 |
| - @((context as MyDdlModel).ExtraField) |
76 |
| - </ItemTemplate> |
77 |
| -</TelerikDropDownList> |
78 |
| -
|
79 |
| -
|
80 |
| -@code { |
81 |
| - public class MyDdlModel |
82 |
| - { |
83 |
| - public int MyValueField { get; set; } |
84 |
| - public string MyTextField { get; set; } |
85 |
| - public string ExtraField { get; set; } |
86 |
| - } |
87 |
| -
|
88 |
| - IEnumerable<MyDdlModel> myDdlData = Enumerable.Range(1, 20).Select(x => |
89 |
| - new MyDdlModel |
90 |
| - { |
91 |
| - MyTextField = "item " + x, |
92 |
| - MyValueField = x, |
93 |
| - ExtraField = "more item info " + x |
94 |
| - } |
95 |
| - ); |
96 |
| -} |
97 |
| -```` |
98 |
| - |
99 |
| ->caption The result from the code snippet above |
100 |
| -
|
101 |
| - |
102 |
| - |
103 |
| -## Header |
104 |
| - |
105 |
| -The header is content that you can place above the list of items inside the dropdownlist element. It is always visible when the dropdown is expanded. By default it is empty. |
106 |
| - |
107 |
| ->caption Header Example |
108 |
| -
|
109 |
| -````CSHTML |
110 |
| -Define a header in the dropdown |
111 |
| -
|
112 |
| -<TelerikDropDownList Data="@myDdlData" TextField="MyTextField" ValueField="MyValueField" Value="1"> |
113 |
| - <HeaderTemplate>My list header.</HeaderTemplate> |
114 |
| -</TelerikDropDownList> |
115 |
| -
|
116 |
| -
|
117 |
| -@code { |
118 |
| - public class MyDdlModel |
119 |
| - { |
120 |
| - public int MyValueField { get; set; } |
121 |
| - public string MyTextField { get; set; } |
122 |
| - } |
123 |
| -
|
124 |
| - IEnumerable<MyDdlModel> myDdlData = Enumerable.Range(1, 20).Select(x => |
125 |
| - new MyDdlModel |
126 |
| - { |
127 |
| - MyTextField = "item " + x, |
128 |
| - MyValueField = x |
129 |
| - } |
130 |
| - ); |
131 |
| -} |
132 |
| -```` |
133 |
| - |
134 |
| ->caption The result from the code snippet above |
135 |
| -
|
136 |
| - |
137 |
| - |
138 |
| -## Footer |
139 |
| - |
140 |
| -The footer is content that you can place below the list of items inside the dropdownlist element. It is always visible when the dropdown is expanded. By default it is empty. |
141 |
| - |
142 |
| ->caption Footer Example |
| 19 | +>caption Filtering in the ComboBox |
143 | 20 |
|
144 | 21 | ````CSHTML
|
145 |
| -Define dropdown footer |
| 22 | +@* Type something in the input to see items whose text contains only the typed string, for example "uct 2" *@ |
146 | 23 |
|
147 |
| -<TelerikDropDownList Data="@myDdlData" TextField="MyTextField" ValueField="MyValueField" Value="1"> |
148 |
| - <FooterTemplate>My list footer.</FooterTemplate> |
149 |
| -</TelerikDropDownList> |
| 24 | +@SelectedValue |
| 25 | +<br /> |
150 | 26 |
|
| 27 | +<TelerikComboBox Data="@Data" |
| 28 | + Filterable="true" |
| 29 | + Placeholder="Find product by typing part of its name" |
| 30 | + @bind-Value="@SelectedValue" TextField="ProductName" ValueField="ProductId"> |
| 31 | +</TelerikComboBox> |
151 | 32 |
|
152 | 33 | @code {
|
153 |
| - public class MyDdlModel |
154 |
| - { |
155 |
| - public int MyValueField { get; set; } |
156 |
| - public string MyTextField { get; set; } |
157 |
| - } |
158 |
| -
|
159 |
| - IEnumerable<MyDdlModel> myDdlData = Enumerable.Range(1, 20).Select(x => |
160 |
| - new MyDdlModel |
161 |
| - { |
162 |
| - MyTextField = "item " + x, |
163 |
| - MyValueField = x |
164 |
| - } |
165 |
| - ); |
| 34 | + public List<Product> Data { get; set; } |
| 35 | + public int? SelectedValue { get; set; } |
| 36 | +
|
| 37 | + protected override void OnInitialized() |
| 38 | + { |
| 39 | + List<Product> products = new List<Product>(); |
| 40 | + for (int i = 0; i < 20; i++) |
| 41 | + { |
| 42 | + products.Add(new Product() |
| 43 | + { |
| 44 | + ProductId = i, |
| 45 | + ProductName = $"Product {i}" |
| 46 | + }); |
| 47 | + } |
| 48 | +
|
| 49 | + Data = products; |
| 50 | + base.OnInitialized(); |
| 51 | + } |
| 52 | +
|
| 53 | + public class Product |
| 54 | + { |
| 55 | + public int ProductId { get; set; } |
| 56 | + public string ProductName { get; set; } |
| 57 | + } |
166 | 58 | }
|
167 | 59 | ````
|
168 | 60 |
|
169 |
| ->caption The result from the code snippet above |
170 |
| -
|
171 |
| - |
172 | 61 |
|
173 | 62 | ## See Also
|
174 | 63 |
|
175 |
| - * [Live Demo: DropDownList Validation](https://demos.telerik.com/blazor-ui/dropdownlist/validation) |
| 64 | + * [Live Demo: ComboBox Filtering](https://demos.telerik.com/blazor-ui/combobox/filtering) |
176 | 65 |
|
177 | 66 |
|
0 commit comments