Skip to content

Commit f1c6ce0

Browse files
authored
MudDataGrid: Fix Loading Indicator scrolls out of view with FixedHeader (MudBlazor#10838)
1 parent b548d6b commit f1c6ce0

File tree

4 files changed

+90
-8
lines changed

4 files changed

+90
-8
lines changed

src/MudBlazor.Docs/Pages/Components/DataGrid/DataGridPage.razor

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,5 +369,23 @@
369369
</SectionContent>
370370
</DocsPageSection>
371371

372+
<DocsPageSection>
373+
<SectionHeader Title="Other Options">
374+
<Description>
375+
There are many options available for the <CodeInline>&lt;MudDataGrid></CodeInline> that are not covered in the examples above.
376+
The <CodeInline>&lt;ColGroup></CodeInline> component allows you to apply a span or style property to multiple columns. However,
377+
the available styles are limited to a few CSS properties, including width, visibility, background, and border. Additionally, the
378+
`span` property enables a column to extend across multiple columns. The <CodeInline>Loading</CodeInline> property displays a loading
379+
indicator while the data grid is retrieving data. You can bind this attribute to a `bool` variable set to `true` when initializing
380+
the page and toggle it once the data has loaded. The <CodeInline>FixedHeader</CodeInline> property ensures that the header remains
381+
fixed at the top of the grid, even when scrolling. These are just a few of the many available options. For a complete list and
382+
additional details, refer to the <MudLink Href="components/datagrid#api">API</MudLink> documentation above.
383+
</Description>
384+
</SectionHeader>
385+
<SectionContent DarkenBackground="true" Code="@nameof(DataGridOtherOptionsExample)" ShowCode="false" Block="true" FullWidth="true">
386+
<DataGridOtherOptionsExample />
387+
</SectionContent>
388+
</DocsPageSection>
389+
372390
</DocsPageContent>
373391
</DocsPage>
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
@namespace MudBlazor.Docs.Examples
2+
3+
<MudDataGrid Items="@_persons" T="Person" Loading="_loading"
4+
Filterable Dense="@_dense" FixedHeader ShowMenuIcon Height="350px">
5+
<ToolBarContent>
6+
<MudSwitch Class="ml-auto" @bind-Value="@_dense" Label="Dense" />
7+
<MudSwitch Class="ml-2 mr-auto" @bind-Value="@_loading" Label="Loading" />
8+
</ToolBarContent>
9+
<ColGroup>
10+
<col style="width: 50px; background: var(--mud-palette-tertiary);" />
11+
<col />
12+
</ColGroup>
13+
<Columns>
14+
<PropertyColumn Property="x => x.Id" Title="Id" />
15+
<PropertyColumn Property="x => x.Name" Title="Name" />
16+
</Columns>
17+
<PagerContent>
18+
<MudDataGridPager T="Person" PageSizeOptions="new int[] {10, 1000}" />
19+
</PagerContent>
20+
</MudDataGrid>
21+
22+
@code {
23+
private bool _dense = false;
24+
private bool _loading = true;
25+
List<Person> _persons = Enumerable.Repeat(0, 100)
26+
.Select((_, i) => new Person { Id = i, Name = $"Name{i}" })
27+
.ToList();
28+
29+
private async Task<GridData<Person>> ServerReload(GridState<Person> state)
30+
{
31+
await Task.CompletedTask;
32+
33+
return new GridData<Person>
34+
{
35+
TotalItems = _persons.Count,
36+
Items = _persons
37+
};
38+
}
39+
40+
public class Person
41+
{
42+
public int Id { get; set; }
43+
44+
public string Name { get; set; } = default!;
45+
}
46+
}

src/MudBlazor.UnitTests.Viewer/TestComponents/DataGrid/DataGridFixedHeaderFilterTest.razor

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
11
<MudCard Style="height:300px">
22
</MudCard>
33

4-
5-
<MudDataGrid Items="@_persons" T="Person"
6-
Filterable Dense="@_dense" FixedHeader ShowMenuIcon Height="350px">
4+
<MudDataGrid Items="@_persons" T="Person" Loading="true"
5+
Filterable Dense="@_dense" FixedHeader ShowMenuIcon Height="350px">
76
<Columns>
87
<PropertyColumn Property="x => x.Id" Title="Id" />
98
<PropertyColumn Property="x => x.Name" Title="Name" />
10-
119
</Columns>
1210
<PagerContent>
13-
<MudDataGridPager T="Person" SetRowsPerPage="new int[] {10, 1000}" />
11+
<MudDataGridPager T="Person" PageSizeOptions="new int[] {10, 1000}" />
1412
</PagerContent>
1513
</MudDataGrid>
1614

1715
<MudSwitch @bind-Value="@_dense" Label="Dense" />
1816

1917
@code {
2018
private bool _dense = false;
21-
public static string __description__ = " Filter popover positioning when DataGrid FixedHeader is true ";
19+
public static string __description__ = " Filter popover positioning when DataGrid FixedHeader is true as well as loading indicator ";
2220
List<Person> _persons = [];
2321

2422
protected override void OnInitialized()
@@ -46,4 +44,4 @@ Filterable Dense="@_dense" FixedHeader ShowMenuIcon Height="350px">
4644

4745
public string Name { get; set; } = default!;
4846
}
49-
}
47+
}

src/MudBlazor/Styles/components/_table.scss

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,19 @@
280280
top: 0;
281281
}
282282

283+
& * .mud-table-loading {
284+
background-color: var(--mud-palette-surface);
285+
position: sticky;
286+
z-index: 2;
287+
top: 59px;
288+
}
289+
283290
& * .mud-filter-panel-cell {
284-
top: 58px;
291+
top: 59px;
292+
}
293+
// If .mud-table-loading exists, move .mud-filter-panel-cell down
294+
table:has(.mud-table-loading) & * .mud-filter-panel-cell {
295+
top: 63px;
285296
}
286297

287298
& * .mud-table-cell.sticky-left,
@@ -296,9 +307,18 @@
296307
.mud-table-sticky-header.mud-table-dense {
297308
& * .mud-table-root {
298309
.mud-table-head {
310+
311+
& * .mud-table-loading {
312+
top: 39px;
313+
}
314+
299315
& * .mud-filter-panel-cell {
300316
top: 39px;
301317
}
318+
319+
table:has(.mud-table-loading) & * .mud-filter-panel-cell {
320+
top: 43px;
321+
}
302322
}
303323
}
304324
}

0 commit comments

Comments
 (0)