Skip to content

Commit 6ee967d

Browse files
docs(autoComplete): filtering
1 parent e869b54 commit 6ee967d

File tree

2 files changed

+38
-43
lines changed

2 files changed

+38
-43
lines changed

components/autocomplete/filter.md

Lines changed: 34 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -10,57 +10,50 @@ position: 3
1010

1111
# AutoComplete Filter
1212

13-
The ComboBox component allows the user to filter the available items by their text, so they can find the one they need faster.
13+
The AutoComplete component can filter the available suggestions according to the current user input, so they can find the one they need faster. To see the difference in behavior, visit the [Live Demo: AutoComplete Filtering](https://demos.telerik.com/blazor-ui/autocomplete/filtering) page.
1414

15-
To enable filtering, set the `Filterable` parameter to `true`.
15+
To enable filtering, set the `Filterable` parameter to `true`. The filter operator is `starts with`, and it ignores casing.
1616

17-
The filter operator is `contains`, it looks in the `TextField`, and filtering is reset when the dropdown closes.
17+
To control when the filter list appears, set the `MinLength` parameter. This can be useful if you have a very large list of data.
1818

19-
>caption Filtering in the ComboBox
19+
>caption Filtering in the AutoComplete
2020
2121
````CSHTML
22-
@* Type something in the input to see items whose text contains only the typed string, for example "uct 2" *@
23-
24-
@SelectedValue
25-
<br />
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>
32-
33-
@code {
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-
}
22+
@* as you type "de", you will only get "Developer" and "Designer" as suggestions instead of the full list *@
23+
24+
<TelerikAutoComplete Data="@Suggestions" @bind-Value="@TheValue"
25+
Filterable="true"
26+
Placeholder="Write 'de' to see the filtering" ClearButton="true" />
27+
28+
@code{
29+
string TheValue { get; set; }
30+
31+
List<string> Suggestions { get; set; } = new List<string> {
32+
"Manager", "Developer", "QA", "Technical Writer", "Support Engineer", "Sales Agent", "Architect", "Designer"
33+
};
5834
}
5935
````
6036

37+
>caption Filtering with MinLength
38+
39+
````CSHTML
40+
@* On the first keystroke, there will be no suggestions, then you will only get "Developer" and "Designer" as you write "de" *@
41+
42+
<TelerikAutoComplete Data="@Suggestions" @bind-Value="@TheValue"
43+
Filterable="true" MinLength="2"
44+
Placeholder="Write 'de' to see the filtering" ClearButton="true" />
45+
46+
@code{
47+
string TheValue { get; set; }
48+
49+
List<string> Suggestions { get; set; } = new List<string> {
50+
"Manager", "Developer", "QA", "Technical Writer", "Support Engineer", "Sales Agent", "Architect", "Designer"
51+
};
52+
}
53+
````
6154

6255
## See Also
6356

64-
* [Live Demo: ComboBox Filtering](https://demos.telerik.com/blazor-ui/combobox/filtering)
57+
* [Live Demo: AutoComplete Filtering](https://demos.telerik.com/blazor-ui/autocomplete/filtering)
6558

6659

components/autocomplete/overview.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ User input: @TheValue
3131
@code{
3232
string TheValue { get; set; }
3333
34-
List<string> Suggestions { get; set; } = new List<string>
35-
{ "Manager", "Developer", "QA", "Technical Writer", "Support Engineer", "Sales Agent", "Architect", "Designer" };
34+
List<string> Suggestions { get; set; } = new List<string> {
35+
"Manager", "Developer", "QA", "Technical Writer", "Support Engineer", "Sales Agent", "Architect", "Designer"
36+
};
3637
}
3738
````
3839

@@ -51,6 +52,7 @@ The AutoComplete is a generic component and its type is determined by the type o
5152
* `Data` - allows you to provide the data source. Required.
5253
* `Enabled` - whether the component is enabled.
5354
* `Filterable` - whether [filtering]({%slug autocomplete-filter%}) is enabled for the end user (suggestions will get narrowed down as they type).
55+
* `MinLength` - how many characters the text has to be before the suggestions list appears. Cannot be `0`. Often works together with [filtering]({%slug autocomplete-filter%}).
5456
* `Placeholder` - the text the user sees as a hint when there is no text in the input.
5557
* `PopupHeight` - the height of the expanded dropdown list element.
5658
* `PopupWidth` - the width of the expanded dropdown list element.

0 commit comments

Comments
 (0)