Skip to content

Commit 281318f

Browse files
github-actions[bot]dimodiikoevska
authored
Merge dimodi-grid-loadercontainer-2486 into production (#2489)
* docs(grid): Revamp Grid Loading animation article * Update components/grid/loading-animation.md Co-authored-by: Iva Stefanova Koevska-Atanasova <[email protected]> * Update components/grid/loading-animation.md Co-authored-by: Iva Stefanova Koevska-Atanasova <[email protected]> * Update components/grid/loading-animation.md Co-authored-by: Iva Stefanova Koevska-Atanasova <[email protected]> --------- Co-authored-by: Dimo Dimov <[email protected]> Co-authored-by: Iva Stefanova Koevska-Atanasova <[email protected]>
1 parent d84b527 commit 281318f

File tree

1 file changed

+73
-30
lines changed

1 file changed

+73
-30
lines changed

components/grid/loading-animation.md

Lines changed: 73 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,66 +10,109 @@ 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 during data operations that take more than 600ms to complete. This improves the user experience with a visual hint that the requested action is still running and prevents repetitive user actions.
1414

15-
The data operations that trigger the loading animation include:
15+
The animation appears as a loading indicator over the Blazor Data Grid.
16+
17+
## Basics
18+
19+
The Grid `EnableLoaderContainer` parameter determines if the component will show a built-in LoaderContainer for long-running operations. The loading animation is enabled by default. The data operations that trigger the loading animation include:
1620

1721
* [Paging]({%slug components/grid/features/paging%})
1822
* [Filtering]({%slug components/grid/filtering%})
1923
* [Sorting]({%slug components/grid/features/sorting%})
2024
* [Grouping]({%slug components/grid/features/grouping%})
2125
* [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%})
26+
* [Creating, deleting or editing records]({%slug components/grid/editing/overview%})
27+
28+
## Show LoaderContainer on Initial Load
29+
30+
The Grid does 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. An initial automatic loading sign can either show indefinitely, or it could prevent the user from altering any saved Grid state (such as changing filters).
31+
32+
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).
33+
34+
## Example
2535

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).
36+
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.
2737

28-
>caption Grid Loading Animation
38+
>caption Using an external and the built-in Grid loading animation
2939
3040
````CSHTML
3141
@using Telerik.DataSource
3242
@using Telerik.DataSource.Extensions
3343
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>
44+
<p><label><TelerikCheckBox @bind-Value="@EnableGridLoaderContainer" /> Enable Built-in Grid LoaderContainer</label></p>
45+
46+
<div style="position:relative">
47+
@*
48+
This LoaderContainer is used only during initial data load.
49+
The position:relative style on the parent DIV makes the LoaderContainer cover only the Grid.
50+
The LoaderContainer configuration and Template matches the built-in Grid loading animation.
51+
*@
52+
<TelerikLoaderContainer OverlayThemeColor="@ThemeConstants.Loader.ThemeColor.Light"
53+
Visible="@LoaderContainerVisible">
54+
<Template>
55+
<TelerikLoader Type="@LoaderType.InfiniteSpinner"
56+
Size="@ThemeConstants.Loader.Size.Large" />
57+
</Template>
58+
</TelerikLoaderContainer>
59+
60+
<TelerikGrid OnRead="@OnGridRead"
61+
TItem="@Product"
62+
EnableLoaderContainer="@EnableGridLoaderContainer"
63+
Height="280px"
64+
Pageable="true"
65+
PageSize="5"
66+
Sortable="true">
67+
<GridColumns>
68+
<GridColumn Field="@nameof(Product.Name)" />
69+
<GridColumn Field="@nameof(Product.Price)" DisplayFormat="{0:C2}" />
70+
<GridColumn Field="@nameof(Product.Quantity)" />
71+
</GridColumns>
72+
</TelerikGrid>
73+
</div>
4574
4675
@code {
47-
List<GridModel> AllData { get; set; }
48-
bool ShowLoading { get; set; } = true;
76+
private List<Product> GridData { get; set; } = new();
77+
78+
private bool EnableGridLoaderContainer { get; set; } = true;
79+
private bool LoaderContainerVisible { get; set; } = true;
4980
50-
async Task GetData(GridReadEventArgs args)
81+
private async Task OnGridRead(GridReadEventArgs args)
5182
{
83+
// Simulate network delay.
5284
await Task.Delay(2000);
53-
DataSourceResult result = AllData.ToDataSourceResult(args.Request);
85+
86+
DataSourceResult result = await GridData.ToDataSourceResultAsync(args.Request);
87+
5488
args.Data = result.Data;
5589
args.Total = result.Total;
90+
args.AggregateResults = result.AggregateResults;
91+
92+
// Hide the initial external LoaderContainer.
93+
LoaderContainerVisible = false;
5694
}
5795
5896
protected override void OnInitialized()
5997
{
60-
AllData = Enumerable.Range(1, 30).Select(x => new GridModel
98+
for (int i = 1; i <= 30; i++)
6199
{
62-
Id = x,
63-
Text = "Text " + x
64-
}).ToList();
65-
66-
base.OnInitialized();
100+
GridData.Add(new Product()
101+
{
102+
Id = i,
103+
Name = $"Name {i}",
104+
Price = Random.Shared.Next(1, 100) * 1.23m,
105+
Quantity = Random.Shared.Next(0, 1000)
106+
});
107+
}
67108
}
68109
69-
public class GridModel
110+
public class Product
70111
{
71112
public int Id { get; set; }
72-
public string Text { get; set; }
113+
public string Name { get; set; } = string.Empty;
114+
public decimal Price { get; set; }
115+
public int Quantity { get; set; }
73116
}
74117
}
75118
````

0 commit comments

Comments
 (0)