Skip to content

Commit 6b4342c

Browse files
authored
docs(grid): Revamp Grid Loading animation article
1 parent bdcd99a commit 6b4342c

File tree

1 file changed

+69
-30
lines changed

1 file changed

+69
-30
lines changed

components/grid/loading-animation.md

Lines changed: 69 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,66 +10,105 @@ position: 90
1010

1111
# Loading Animation
1212

13-
The loading animation indicates a data operation that requires more than 600ms to complete. The indicator appears as a loading sign over the Blazor Data Grid. The loading animation improves user experience with a visual hint that the requested action is still executing. The feature can prevent repetitive user actions.
13+
The Grid can show a loading animation to indicate data operations that take more than 600ms to complete. The indicator appears as a loading sign over the Blazor Data Grid. The loading animation improves user experience with a visual hint that the requested action is still executing. The feature can prevent repetitive user actions.
1414

15-
The data operations that trigger the loading animation include:
15+
## Basics
16+
17+
The Grid `EnableLoaderContainer` parameter determines if the component will show a built-in LoaderContainer for long operations. The loading animation is enabled by detault. The data operations that trigger the loading animation include:
1618

1719
* [Paging]({%slug components/grid/features/paging%})
1820
* [Filtering]({%slug components/grid/filtering%})
1921
* [Sorting]({%slug components/grid/features/sorting%})
2022
* [Grouping]({%slug components/grid/features/grouping%})
2123
* [Expanding groups with load-on-demand]({%slug grid-group-lod%})
22-
* [Editing]({%slug components/grid/editing/overview%})
23-
* [Inserting]({%slug components/grid/editing/overview%})
24-
* [Deleting records]({%slug components/grid/editing/overview%})
24+
* [Creating, deleting or editing records]({%slug components/grid/editing/overview%})
25+
26+
## Show LoaderContainer on Initial Load
27+
28+
The Grid will not display a loading animation during its initial rendering and data load. The component cannot know when or even if data will be provided to it, especially when using the Grid `Data` parameter. Initial automatic loading sign can either show indefinitely, or it could prevent the user from altering any saved Grid state (such as changing filters). If you want to display a loading animation on initial load, you can use a [LoaderContainer component]({%slug loadercontainer-overview%}). See the example below or the [Grid Loading Animation Live Demo](https://demos.telerik.com/blazor-ui/grid/loading-animation).
2529

26-
The Grid will not display a loading animation during its initial rendering. The component cannot know when or even if data will be provided to it. Initial automatic loading sign can either show indefinitely, or it could prevent the user from altering any saved Grid state (such as changing filters). If you want a loading animation on the initial load, you can use a [LoaderContainer component]({%slug loadercontainer-overview%}#basic-loadercontainer). See the [Grid Loading Animation Live Demo](https://demos.telerik.com/blazor-ui/grid/loading-animation).
30+
## Example
2731

28-
>caption Grid Loading Animation
32+
The following example binds the Grid with an [`OnRead` event handler]({%slug common-features-data-binding-onread%}). To show an external initial [LoaderContainer over the Grid]({%slug loadercontainer-overview%}#fill-a-parent-container) when using the `Data` parameter, you can control the LoaderContainer's rendering or visibility, depending on whether the data collection is null.
33+
34+
>caption Using an external and the built-in Grid loading animation
2935
3036
````CSHTML
3137
@using Telerik.DataSource
3238
@using Telerik.DataSource.Extensions
3339
34-
<p><label><TelerikCheckBox @bind-Value="@ShowLoading" /> Show Loading</label></p>
35-
36-
<TelerikGrid TItem="@GridModel"
37-
OnRead="@GetData"
38-
EnableLoaderContainer="@ShowLoading"
39-
Pageable="true"
40-
Sortable="true">
41-
<GridColumns>
42-
<GridColumn Field="Text" />
43-
</GridColumns>
44-
</TelerikGrid>
40+
<p><label><TelerikCheckBox @bind-Value="@EnableGridLoaderContainer" /> Enable Built-in Grid LoaderContainer</label></p>
41+
42+
<div style="position:relative">
43+
@*
44+
This LoaderContainer is used only during initial data load.
45+
The position:relative style on the parent DIV makes the LoaderContainer cover only the Grid.
46+
The LoaderContainer configuration and Template matches the built-in Grid loading animation.
47+
*@
48+
<TelerikLoaderContainer OverlayThemeColor="@ThemeConstants.Loader.ThemeColor.Light"
49+
Visible="@LoaderContainerVisible">
50+
<Template>
51+
<TelerikLoader Type="@LoaderType.InfiniteSpinner"
52+
Size="@ThemeConstants.Loader.Size.Large" />
53+
</Template>
54+
</TelerikLoaderContainer>
55+
56+
<TelerikGrid OnRead="@OnGridRead"
57+
TItem="@Product"
58+
EnableLoaderContainer="@EnableGridLoaderContainer"
59+
Height="280px"
60+
Pageable="true"
61+
PageSize="5"
62+
Sortable="true">
63+
<GridColumns>
64+
<GridColumn Field="@nameof(Product.Name)" />
65+
<GridColumn Field="@nameof(Product.Price)" DisplayFormat="{0:C2}" />
66+
<GridColumn Field="@nameof(Product.Quantity)" />
67+
</GridColumns>
68+
</TelerikGrid>
69+
</div>
4570
4671
@code {
47-
List<GridModel> AllData { get; set; }
48-
bool ShowLoading { get; set; } = true;
72+
private List<Product> GridData { get; set; } = new();
4973
50-
async Task GetData(GridReadEventArgs args)
74+
private bool EnableGridLoaderContainer { get; set; } = true;
75+
private bool LoaderContainerVisible { get; set; } = true;
76+
77+
private async Task OnGridRead(GridReadEventArgs args)
5178
{
79+
// Simulate network delay.
5280
await Task.Delay(2000);
53-
DataSourceResult result = AllData.ToDataSourceResult(args.Request);
81+
82+
DataSourceResult result = await GridData.ToDataSourceResultAsync(args.Request);
83+
5484
args.Data = result.Data;
5585
args.Total = result.Total;
86+
args.AggregateResults = result.AggregateResults;
87+
88+
// Hide the initial external LoaderContainer.
89+
LoaderContainerVisible = false;
5690
}
5791
5892
protected override void OnInitialized()
5993
{
60-
AllData = Enumerable.Range(1, 30).Select(x => new GridModel
94+
for (int i = 1; i <= 30; i++)
6195
{
62-
Id = x,
63-
Text = "Text " + x
64-
}).ToList();
65-
66-
base.OnInitialized();
96+
GridData.Add(new Product()
97+
{
98+
Id = i,
99+
Name = $"Name {i}",
100+
Price = Random.Shared.Next(1, 100) * 1.23m,
101+
Quantity = Random.Shared.Next(0, 1000)
102+
});
103+
}
67104
}
68105
69-
public class GridModel
106+
public class Product
70107
{
71108
public int Id { get; set; }
72-
public string Text { get; set; }
109+
public string Name { get; set; } = string.Empty;
110+
public decimal Price { get; set; }
111+
public int Quantity { get; set; }
73112
}
74113
}
75114
````

0 commit comments

Comments
 (0)