|
1 | 1 | <div style="height: 400px; max-width: 800px; overflow-y: scroll;"> |
2 | | - <FluentDataGrid @ref="grid" |
3 | | - Items=@items |
4 | | - Virtualize="true" |
5 | | - DisplayMode="DataGridDisplayMode.Table" |
6 | | - Style="width: 100%;" |
7 | | - ItemSize="54" |
8 | | - GenerateHeader="@DataGridGeneratedHeaderType.Sticky"> |
9 | | - <ChildContent> |
10 | | - <PropertyColumn Width="25%" Property="@(c => c.Item1)" Sortable="true" /> |
11 | | - <PropertyColumn Width="25%" Property="@(c => c.Item2)" /> |
12 | | - <PropertyColumn Width="25%" Property="@(c => c.Item3)" Align="DataGridCellAlignment.Center" /> |
13 | | - <PropertyColumn Width="25%" Property="@(c => c.Item4)" Align="DataGridCellAlignment.End" /> |
14 | | - </ChildContent> |
15 | | - <EmptyContent> |
16 | | - <FluentIcon Value="@(new Icons.Filled.Size24.Crown())" Color="@Color.Primary" /> Nothing to see here. Carry on! |
17 | | - </EmptyContent> |
18 | | - <LoadingContent> |
19 | | - <FluentStack Orientation="Orientation.Vertical" HorizontalAlignment="HorizontalAlignment.Center"> |
20 | | - Loading...<br /> |
21 | | - <FluentProgressBar Width="240px" /> |
22 | | - </FluentStack> |
23 | | - </LoadingContent> |
24 | | - </FluentDataGrid> |
| 2 | + <FluentDataGrid @ref="grid" |
| 3 | + Items=@items |
| 4 | + Virtualize="true" |
| 5 | + DisplayMode="DataGridDisplayMode.Table" |
| 6 | + Style="width: 100%;" |
| 7 | + ItemSize="54" |
| 8 | + GenerateHeader="@DataGridGeneratedHeaderType.Sticky"> |
| 9 | + <ChildContent> |
| 10 | + <PropertyColumn Width="25%" Property="@(c => c.Item1)" Sortable="true" /> |
| 11 | + <PropertyColumn Width="25%" Property="@(c => c.Item2)" /> |
| 12 | + <PropertyColumn Width="25%" Property="@(c => c.Item3)" Align="DataGridCellAlignment.Center" /> |
| 13 | + <PropertyColumn Width="25%" Property="@(c => c.Item4)" Align="DataGridCellAlignment.End" /> |
| 14 | + </ChildContent> |
| 15 | + <EmptyContent> |
| 16 | + <FluentIcon Value="@(new Icons.Filled.Size24.Crown())" Color="@Color.Primary" /> Nothing to see here. Carry on! |
| 17 | + </EmptyContent> |
| 18 | + <LoadingContent> |
| 19 | + <FluentStack Orientation="Orientation.Vertical" HorizontalAlignment="HorizontalAlignment.Center"> |
| 20 | + Loading...<br /> |
| 21 | + <FluentProgressBar Width="240px" /> |
| 22 | + </FluentStack> |
| 23 | + </LoadingContent> |
| 24 | + </FluentDataGrid> |
25 | 25 | </div> |
26 | 26 | <br /> |
27 | | -<FluentSwitch @ref="_clearToggle" |
28 | | - @bind-Value="@_clearItems" |
29 | | - @bind-Value:after="ToggleItems" |
30 | | - Label="@switchLabel"> |
31 | | -</FluentSwitch> |
32 | | -<FluentButton OnClick="SimulateDataLoading">Simulate data loading</FluentButton> |
| 27 | +<FluentStack Orientation="Orientation.Horizontal" HorizontalGap="10px" VerticalAlignment="VerticalAlignment.Center"> |
| 28 | + <FluentSwitch @ref="_clearToggle" |
| 29 | + @bind-Value="@_clearItems" |
| 30 | + @bind-Value:after="ToggleItems" |
| 31 | + Label="@switchLabel"> |
| 32 | + </FluentSwitch> |
| 33 | + <FluentButton OnClick="SimulateDataLoading">Simulate data loading</FluentButton> |
| 34 | +</FluentStack> |
33 | 35 |
|
34 | 36 | @code { |
35 | | - FluentDataGrid<SampleGridData>? grid; |
36 | | - FluentSwitch? _clearToggle; |
37 | | - string switchLabel = "Clear data"; |
| 37 | + FluentDataGrid<SampleGridData>? grid; |
| 38 | + FluentSwitch? _clearToggle; |
| 39 | + string switchLabel = "Clear data"; |
38 | 40 |
|
39 | | - bool _clearItems = false; |
40 | | - public record SampleGridData(string Item1, string Item2, string Item3, string Item4); |
| 41 | + bool _clearItems = false; |
| 42 | + public record SampleGridData(string Item1, string Item2, string Item3, string Item4); |
41 | 43 |
|
42 | | - IQueryable<SampleGridData>? items = Enumerable.Empty<SampleGridData>().AsQueryable(); |
| 44 | + IQueryable<SampleGridData>? items = Enumerable.Empty<SampleGridData>().AsQueryable(); |
43 | 45 |
|
44 | | - private IQueryable<SampleGridData> GenerateSampleGridData(int size) |
45 | | - { |
46 | | - SampleGridData[] data = new SampleGridData[size]; |
| 46 | + private IQueryable<SampleGridData> GenerateSampleGridData(int size) |
| 47 | + { |
| 48 | + SampleGridData[] data = new SampleGridData[size]; |
47 | 49 |
|
48 | | - for (int i = 0; i < size; i++) |
49 | | - { |
50 | | - data[i] = new SampleGridData($"value {i}-1", $"value {i}-2", $"value {i}-3", $"value {i}-4"); |
51 | | - } |
52 | | - return data.AsQueryable(); |
53 | | - } |
54 | | - protected override void OnInitialized() |
55 | | - { |
56 | | - items = GenerateSampleGridData(5000); |
57 | | - } |
| 50 | + for (int i = 0; i < size; i++) |
| 51 | + { |
| 52 | + data[i] = new SampleGridData($"value {i}-1", $"value {i}-2", $"value {i}-3", $"value {i}-4"); |
| 53 | + } |
| 54 | + return data.AsQueryable(); |
| 55 | + } |
| 56 | + protected override void OnInitialized() |
| 57 | + { |
| 58 | + items = GenerateSampleGridData(5000); |
| 59 | + } |
58 | 60 |
|
59 | | - private void ToggleItems() |
60 | | - { |
61 | | - if (_clearItems) |
62 | | - { |
63 | | - items = null; |
64 | | - switchLabel = "Restore data"; |
65 | | - } |
66 | | - else |
67 | | - { |
68 | | - items = GenerateSampleGridData(5000); |
69 | | - switchLabel = "Clear data"; |
70 | | - } |
71 | | - } |
| 61 | + private void ToggleItems() |
| 62 | + { |
| 63 | + if (_clearItems) |
| 64 | + { |
| 65 | + items = null; |
| 66 | + switchLabel = "Restore data"; |
| 67 | + } |
| 68 | + else |
| 69 | + { |
| 70 | + items = GenerateSampleGridData(5000); |
| 71 | + switchLabel = "Clear data"; |
| 72 | + } |
| 73 | + } |
72 | 74 |
|
73 | | - private async Task SimulateDataLoading() |
74 | | - { |
75 | | - _clearItems = false; |
| 75 | + private async Task SimulateDataLoading() |
| 76 | + { |
| 77 | + _clearItems = false; |
76 | 78 |
|
77 | | - items = null; |
78 | | - grid?.SetLoadingState(true); |
| 79 | + items = null; |
| 80 | + grid?.SetLoadingState(true); |
79 | 81 |
|
80 | | - await Task.Delay(1500); |
| 82 | + await Task.Delay(1500); |
81 | 83 |
|
82 | | - items = GenerateSampleGridData(5000); |
83 | | - grid?.SetLoadingState(false); |
84 | | - } |
| 84 | + items = GenerateSampleGridData(5000); |
| 85 | + grid?.SetLoadingState(false); |
| 86 | + } |
85 | 87 | } |
0 commit comments