Skip to content

Commit 7bcf731

Browse files
dimodiDimo Dimov
andauthored
docs: Document OnRead breaking changes (#712)
* docs: Document OnRead breaking changes * docs: Document OnRead breaking changes 2 * docs: Document OnRead breaking changes 3 * docs: Document OnRead breaking changes 4 Co-authored-by: Dimo Dimov <[email protected]>
1 parent 2f4f30a commit 7bcf731

33 files changed

+705
-1198
lines changed

_contentTemplates/common/dropdowns-virtualization.md

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,59 +5,50 @@ Enabling the UI virtualization feature makes the component reuse a set number of
55
#end
66

77

8-
98
#basics-core
109
This section will explain the parameters and behaviors that are related to the virtualization feature so you can set it up.
1110

1211
>caption To enable UI virtualization, you need to set the following parameters of the component:
1312
1413
* `ScrollMode` - `Telerik.Blazor.DropDownScrollMode` - set it to `DropDownScrollMode.Virtual`. It defaults to the "regular" scrolling.
15-
16-
* `PopupHeight` - `string` - set the height of the popup element to a valid CSS unit. It must **not** be a `null/empty` string.
17-
14+
* `Height` - `string` - [set the height]({%slug common-features/dimensions%}) in the nested **popup settings** tag of the component. It must **not** be a `null/empty` string.
1815
* `ItemHeight` - `decimal` - set it to the height each individual item will have in the dropdown. Make sure to accommodate the content your items will have and any item template.
19-
20-
* `PageSize` - `int` - defines how many items will actually be rendered and reused. The value determines how many items are loaded on each scroll. The number of items must be large enough according to the `ItemHeight` and `PopupHeight` so that there are more items than the dropdown so there is a scrollbar.
16+
* `PageSize` - `int` - defines how many items will actually be rendered and reused. The value determines how many items are loaded on each scroll. The number of items must be large enough according to the `ItemHeight` and popup `Height`, so that there are more items than the dropdown so there is a scrollbar.
2117

2218
You can find a basic example in the [Local Data](#local-data-example) section below.
2319

2420
>caption For working with [remote data](#remote-data-example), you also need:
2521
#end
2622

2723

28-
2924
#value-mapper-text
30-
the component will call this method to request the model that matches the `Value` it has set. This is required because with remote data the `Value` may not be in the initial collection of `Data` that the component has, and so there would otherwise be no way to extract the `DataTextField` from it to render it. Usually, this method will be called on the initial render only to fetch the data item for the current selection.
25+
the component will call this method to request the model that matches the `Value` it has set. This is required because with remote data the `Value` may not be in the initial collection of data that the component has, and so there would otherwise be no way to extract the `DataTextField` from it to render it. Usually, this method will be called on the initial render only to fetch the data item for the current selection.
3126
#end
3227

3328

34-
3529
#remote-data-specifics
36-
* `OnRead` - `EventCallback` - the component will call this event when the user scrolls with the corresponding offset (`Skip`), `PageSize` and any filters. This lets you optimize the data queries and return only what is needed at the moment, when it is needed.
37-
38-
* `TotalCount` - `int` - the total number of items that the dropdown can have. Needs to take into account any current filtering.
30+
* `OnRead` - `EventCallback` - the component will call this event when the user scrolls with the corresponding offset (`Skip`), `PageSize` and any filters. This lets you optimize the data queries and return only what is needed at the moment, when it is needed. Set the `args.Data` and `args.Total` properties of the event argument object.
3931
#end
4032

4133

42-
4334
#limitations
44-
4535
* When the initially selected item/items are on a page different than the first one, opening the dropdown list will NOT scroll the list to the selected item.
46-
4736
#end
4837

4938

50-
5139
#remote-data-sample-intro
5240
This example showcases sample implementations of:
5341

5442
* An async remote service that returns the data. It is mocked by a static class for this example, you can refactor as needed, and you can find examples of serializing it over the wire in <a href="https://github.com/telerik/blazor-ui/tree/master/grid/datasourcerequest-on-server" target="_blank">this collection of sample projects</a> for the grid component - the approach is identical.
55-
5643
* An `OnRead` event handler that calls that service.
57-
5844
#end
5945

6046

6147
#value-mapper-in-remote-example
6248
* A `ValueMapper` that also calls the service.
63-
#end
49+
#end
50+
51+
52+
#value-in-onread
53+
>important The `OnRead` handler should change **only the data** of the component, and **not** other parameters such as `Value`. This can lead to issues with the asynchronous nature of the event, and race conditions can occur with the arrival of the new data. Moreover, such a change is likely to be unexpected by the user and cause bad UX.
54+
#end

common-features/loading-sign.md

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -358,16 +358,15 @@ We understand, however, that you might want to disable this feature in some case
358358
@* The data operations (such as filtering, sorting, paging) are slow in this example, but there is no loading sign *@
359359
360360
<TelerikGrid EnableLoaderContainer="false"
361-
Data=@GridData TotalCount=@Total OnRead=@ReadItems
362-
[email protected] Sortable=true Pageable=true EditMode="@GridEditMode.Inline">
361+
TItem="@Employee" OnRead="@ReadItems"
362+
FilterMode="@GridFilterMode.FilterRow"
363+
Sortable="true"
364+
Pageable="true">
363365
<GridColumns>
364366
<GridColumn Field=@nameof(Employee.ID) />
365367
<GridColumn Field=@nameof(Employee.Name) Title="Name" />
366368
<GridColumn Field=@nameof(Employee.HireDate) Title="Hire Date" />
367369
</GridColumns>
368-
<GridToolBar>
369-
<GridCommandButton Command="Add" Icon="add">Add Employee</GridCommandButton>
370-
</GridToolBar>
371370
</TelerikGrid>
372371
373372
@* Everything else here is sample data binding *@
@@ -376,8 +375,6 @@ We understand, however, that you might want to disable this feature in some case
376375
377376
@code {
378377
public List<Employee> SourceData { get; set; }
379-
public List<Employee> GridData { get; set; }
380-
public int Total { get; set; } = 0;
381378
382379
protected override void OnInitialized()
383380
{
@@ -390,15 +387,10 @@ We understand, however, that you might want to disable this feature in some case
390387
391388
var datasourceResult = SourceData.ToDataSourceResult(args.Request);
392389
393-
GridData = (datasourceResult.Data as IEnumerable<Employee>).ToList();
394-
Total = datasourceResult.Total;
395-
396-
StateHasChanged();
390+
args.Data = (datasourceResult.Data as IEnumerable<Employee>).ToList();
391+
args.Total = datasourceResult.Total;
397392
}
398393
399-
//This sample implements only reading of the data. To add the rest of the CRUD operations see
400-
//https://docs.telerik.com/blazor-ui/components/grid/editing/overview
401-
402394
private List<Employee> GenerateData()
403395
{
404396
var result = new List<Employee>();

components/autocomplete/events.md

Lines changed: 48 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ from model: @Role
7777
}
7878
````
7979

80-
8180
## OnChange
8281

8382
The `OnChange` event represents a user action - confirmation of the current value/item. The key differences with `ValueChanged` are:
@@ -121,32 +120,34 @@ You can use the he `OnRead` event to provide data to the component according to
121120

122121
You can also call remote data through async operations.
123122

123+
When using `OnRead`, make sure to set `TItem` and `TValue`.
124+
124125
>caption Custom Data according to the user input in the AutoComplete
125126
126127
````CSHTML
127-
@SelectedValue
128-
<br />
129-
<TelerikAutoComplete Data="@Suggestions"
128+
<p>@AutoCompleteValue</p>
129+
130+
<TelerikAutoComplete TItem="@String"
130131
OnRead="@ReadItems"
132+
@bind-Value="@AutoCompleteValue"
131133
Filterable="true"
132-
Placeholder="Find what you seek by typing"
133-
@bind-Value="@SelectedValue">
134+
Placeholder="Type anything">
134135
</TelerikAutoComplete>
135136
136-
@code{
137-
public string SelectedValue { get; set; }
137+
@code {
138+
public string AutoCompleteValue { get; set; }
138139
List<string> Suggestions { get; set; } = new List<string>();
139140
140141
async Task ReadItems(AutoCompleteReadEventArgs args)
141142
{
142-
if (args.Request.Filters.Count > 0) // there is user filter input, skips providing data on initialization
143+
if (args.Request.Filters.Count > 0) // wait for user filter input
143144
{
144145
Telerik.DataSource.FilterDescriptor filter = args.Request.Filters[0] as Telerik.DataSource.FilterDescriptor;
145146
string userInput = filter.Value.ToString();
146147
string method = filter.Operator.ToString();
147148
148149
//new data collection comes down from the service
149-
Suggestions = await GetSuggestionsData(userInput, method);
150+
args.Data = await GetSuggestionsData(userInput, method);
150151
}
151152
}
152153
@@ -157,7 +158,7 @@ You can also call remote data through async operations.
157158
//sample logic for getting suggestions - here they are generated, you can call a remote service
158159
//for brevity, this example does not use the filter operator, but your actual service can
159160
List<string> suggestionsData = new List<string>();
160-
for (int i = 0; i < 5; i++)
161+
for (int i = 1; i <= 5; i++)
161162
{
162163
suggestionsData.Add($"suggestion {i} for input {userInput}");
163164
}
@@ -172,53 +173,51 @@ You can also call remote data through async operations.
172173
````CSHTML
173174
@using Telerik.DataSource.Extensions
174175
175-
@SelectedValue
176-
<br />
177-
<TelerikAutoComplete Data="@CurrentSuggestions"
178-
OnRead=@ReadItems
179-
Filterable="true"
180-
Placeholder="Find a car by typing part of its make"
181-
@bind-Value="@SelectedValue" ValueField="Make">
176+
<p>@AutoCompleteValue</p>
177+
178+
<TelerikAutoComplete TItem="@Car"
179+
OnRead="@ReadItems"
180+
@bind-Value="@AutoCompleteValue"
181+
ValueField="@nameof(Car.Make)"
182+
Filterable="true"
183+
Placeholder="Type a car brand">
182184
</TelerikAutoComplete>
183185
184186
@code {
185-
public string SelectedValue { get; set; }
187+
public string AutoCompleteValue { get; set; }
186188
List<Car> AllSuggestions { get; set; }
187189
188-
List<Car> CurrentSuggestions { get; set; }
189-
190190
protected async Task ReadItems(AutoCompleteReadEventArgs args)
191191
{
192-
//generate the big data source that we want to narrow down for the user
193-
//in a real case you would probably have fetched it in OnInitializedAsync
194-
if (AllSuggestions == null)
195-
{
196-
AllSuggestions = new List<Car>
197-
{
198-
new Car { Id = 1, Make = "Honda" },
199-
new Car { Id = 2, Make = "Opel" },
200-
new Car { Id = 3, Make = "Audi" },
201-
new Car { Id = 4, Make = "Lancia" },
202-
new Car { Id = 5, Make = "BMW" },
203-
new Car { Id = 6, Make = "Mercedes" },
204-
new Car { Id = 7, Make = "Tesla" },
205-
new Car { Id = 8, Make = "Vw" },
206-
new Car { Id = 9, Make = "Alpha Romeo" },
207-
new Car { Id = 10, Make = "Chevrolet" },
208-
new Car { Id = 11, Make = "Ford" },
209-
new Car { Id = 12, Make = "Cadillac" },
210-
new Car { Id = 13, Make = "Dodge" },
211-
new Car { Id = 14, Make = "Jeep" },
212-
new Car { Id = 15, Make = "Chrysler" },
213-
new Car { Id = 16, Make = "Lincoln" }
214-
};
215-
}
216-
217-
//use Telerik extension methods to filter the data source based on the request from the component
192+
//using Telerik extension methods to filter the data
218193
var datasourceResult = AllSuggestions.ToDataSourceResult(args.Request);
219-
CurrentSuggestions = (datasourceResult.Data as IEnumerable<Car>).ToList();
194+
args.Data = datasourceResult.Data;
195+
}
196+
197+
protected override void OnInitialized()
198+
{
199+
AllSuggestions = new List<Car> {
200+
new Car { Id = 1, Make = "Honda" },
201+
new Car { Id = 2, Make = "Opel" },
202+
new Car { Id = 3, Make = "Audi" },
203+
new Car { Id = 4, Make = "Lancia" },
204+
new Car { Id = 5, Make = "BMW" },
205+
new Car { Id = 6, Make = "Mercedes" },
206+
new Car { Id = 7, Make = "Tesla" },
207+
new Car { Id = 8, Make = "Vw" },
208+
new Car { Id = 9, Make = "Alpha Romeo" },
209+
new Car { Id = 10, Make = "Chevrolet" },
210+
new Car { Id = 11, Make = "Ford" },
211+
new Car { Id = 12, Make = "Cadillac" },
212+
new Car { Id = 13, Make = "Dodge" },
213+
new Car { Id = 14, Make = "Jeep" },
214+
new Car { Id = 15, Make = "Chrysler" },
215+
new Car { Id = 16, Make = "Lincoln" }
216+
};
217+
218+
base.OnInitialized();
220219
}
221-
220+
222221
public class Car
223222
{
224223
public int Id { get; set; }
@@ -227,8 +226,6 @@ You can also call remote data through async operations.
227226
}
228227
````
229228

230-
231-
232229
## OnBlur
233230

234231
The `OnBlur` event fires when the component loses focus.

components/autocomplete/virtualization.md

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ The AutoComplete @[template](/_contentTemplates/common/dropdowns-virtualization.
2424
![Virtual Scrolling of large local data](images/autocomplete-virtual-scrolling-local.gif)
2525

2626

27-
2827
## Basics
2928

3029
@[template](/_contentTemplates/common/dropdowns-virtualization.md#basics-core)
@@ -37,7 +36,6 @@ The AutoComplete @[template](/_contentTemplates/common/dropdowns-virtualization.
3736
@[template](/_contentTemplates/common/dropdowns-virtualization.md#limitations)
3837

3938

40-
4139
## Local Data Example
4240

4341

@@ -73,8 +71,6 @@ The AutoComplete @[template](/_contentTemplates/common/dropdowns-virtualization.
7371
}
7472
````
7573

76-
77-
7874
## Remote Data Example
7975

8076
@[template](/_contentTemplates/common/dropdowns-virtualization.md#remote-data-sample-intro)
@@ -85,31 +81,30 @@ Run this and see how you can display, scroll and filter over 10k records in the
8581
@using Telerik.DataSource
8682
@using Telerik.DataSource.Extensions
8783
88-
@SelectedValue
89-
<br />
90-
<TelerikAutoComplete Data="@CurentPageOfData"
84+
<p>@AutoCompleteValue</p>
85+
86+
<TelerikAutoComplete TItem="@String"
9187
ScrollMode="@DropDownScrollMode.Virtual"
92-
OnRead="@GetRemoteData"
93-
TotalCount="@TotalItems"
94-
PopupHeight="200px"
9588
ItemHeight="30"
9689
PageSize="20"
97-
98-
@bind-Value="@SelectedValue"
99-
Filterable="true" FilterOperator="@StringFilterOperator.Contains">
90+
OnRead="@GetRemoteData"
91+
@bind-Value="@AutoCompleteValue"
92+
Filterable="true"
93+
FilterOperator="@StringFilterOperator.Contains">
94+
<AutoCompleteSettings>
95+
<AutoCompletePopupSettings Height="300px" />
96+
</AutoCompleteSettings>
10097
</TelerikAutoComplete>
10198
102-
@code{
103-
string SelectedValue { get; set; } = "Name 1234"; // pre-select an item to showcase it works like in a regular textbox
104-
List<string> CurentPageOfData { get; set; }
105-
int TotalItems { get; set; }
99+
@code {
100+
string AutoCompleteValue { get; set; } = "Name 1234"; // pre-select an item to showcase it works like in a regular textbox
106101
107-
async Task GetRemoteData(AutoCompleteReadEventArgs e)
102+
async Task GetRemoteData(AutoCompleteReadEventArgs args)
108103
{
109-
DataEnvelope<string> result = await MyService.GetItems(e.Request);
104+
DataEnvelope<string> result = await MyService.GetItems(args.Request);
110105
111-
CurentPageOfData = result.Data;
112-
TotalItems = result.Total;
106+
args.Data = result.Data;
107+
args.Total = result.Total;
113108
}
114109
115110
// mimics a real service in terms of API appearance, refactor as necessary for your app
@@ -149,6 +144,4 @@ Run this and see how you can display, scroll and filter over 10k records in the
149144

150145
## See Also
151146

152-
* [Live Demo: AutoComplete Virtualization](https://demos.telerik.com/blazor-ui/autocomplete/virtualization)
153-
154-
147+
* [Live Demo: AutoComplete Virtualization](https://demos.telerik.com/blazor-ui/autocomplete/virtualization)

0 commit comments

Comments
 (0)