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
@@ -31,90 +31,200 @@ I also want to implement a minimum filter length, if the input is below that len
31
31
32
32
## Solution
33
33
34
-
Implement logic in the [OnRead event]({%slug components/combobox/events%}#onread) that will debounce the calls to the service with the desired timeout. For example, use a `CancellationTokenSource`.
34
+
There are two ways to implement debouncing:
35
35
36
-
For min filter length, just add a check in the handler for the desired string length (in this example - 2 symbols).
36
+
* Use the built-in ComboBox `DebounceDelay` parameter.
37
+
* Implement logic in the [ComboBox OnRead event]({%slug components/combobox/events%}#onread) to debounce the calls to the data service with the desired timeout. For example, use a `CancellationTokenSource`.
37
38
38
-
>caption Use a `CancellationTokenSource` to debounce OnRead filter calls in the combo box. Add Min Filter Length
39
+
For minimum filter length, add a check in the `OnRead` event handler for the desired string length.
40
+
41
+
>caption Debounce OnRead filter calls in the ComboBox and add minimum filter length.
39
42
40
43
````CSHTML
41
-
@implements IDisposable
42
44
@using System.Threading
43
45
44
-
<p>@SelectedValue</p>
46
+
@using Telerik.DataSource
47
+
@using Telerik.DataSource.Extensions
48
+
49
+
@implements IDisposable
50
+
51
+
<p><code>ComboBoxValue</code>: @ComboBoxValue</p>
52
+
53
+
<p>Debounce inside <code>OnRead</code>:</p>
54
+
55
+
<TelerikComboBox OnRead="@OnComboBoxRead1"
56
+
TItem="@ListItem"
57
+
TValue="@(int?)"
58
+
@bind-Value="@ComboBoxValue"
59
+
TextField="@nameof(ListItem.Text)"
60
+
ValueField="@nameof(ListItem.Id)"
61
+
Filterable="true"
62
+
FilterOperator="@StringFilterOperator.Contains"
63
+
Id="debounce-in-onread"
64
+
Placeholder="Type 2+ letters or numbers to filter..."
65
+
ScrollMode="@DropDownScrollMode.Virtual"
66
+
ItemHeight="32"
67
+
PageSize="20"
68
+
ValueMapper="@ComboBoxValueMapper"
69
+
Width="300px">
70
+
</TelerikComboBox>
45
71
46
-
<TelerikComboBox TItem="@String" TValue="@String"
47
-
OnRead="@ReadItems"
48
-
@bind-Value="@SelectedValue"
72
+
<p>Use <code>DebounceDelay</code>:</p>
73
+
74
+
<TelerikComboBox OnRead="@OnComboBoxRead2"
75
+
TItem="@ListItem"
76
+
TValue="@(int?)"
77
+
@bind-Value="@ComboBoxValue"
78
+
TextField="@nameof(ListItem.Text)"
79
+
ValueField="@nameof(ListItem.Id)"
80
+
DebounceDelay="@ComboBoxDebounceDelay"
49
81
Filterable="true"
50
-
Placeholder="Type anything">
82
+
FilterOperator="@StringFilterOperator.Contains"
83
+
Id="debounce-delay"
84
+
Placeholder="Type 2+ letters or numbers to filter..."
85
+
ScrollMode="@DropDownScrollMode.Virtual"
86
+
ItemHeight="32"
87
+
PageSize="20"
88
+
ValueMapper="@ComboBoxValueMapper"
89
+
Width="300px">
51
90
</TelerikComboBox>
52
91
53
92
@code {
54
-
public string SelectedValue { get; set; }
55
-
CancellationTokenSource tokenSource = new CancellationTokenSource(); // for debouncing the service calls
0 commit comments