Repository navigation
Expand file tree
/
Copy pathUsersGrid.razor
More file actions
60 lines (49 loc) · 2.75 KB
/
Copy pathUsersGrid.razor
File metadata and controls
60 lines (49 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
@page "/users-grid"
<ExampleInfo Route="users-grid"
Lead="Bring your own QuickGrid, and let the toolkit manage the columns.">
<p>
This is the low-level pattern. You write the <code><QuickGrid></code> markup yourself and render
its columns from a <code>ColumnManager<T></code> with <code>@@QuickGridColumns.Columns(...)</code>.
A <code>ColumnSelector</code> gives the user a show/hide UI; call <code>RefreshDataAsync()</code> whenever
the selection changes.
</p>
<ul>
<li><code>ColumnManager<T></code> declares every possible column. Note the mix of helpers below: <code>AddSimple</code>, <code>AddToggleColumn</code>, a shared column set pulled in with <code>AddRange</code>, and the custom <code>AddCountry</code> extension.</li>
<li>The shared set (<code>SharedUserColumnManager.Instance</code>) is a <em>single</em> instance reused by this page and by <a href="users-grid-wrapper">QuickGridWrapper</a>. <code>AddRange</code> copies each column in, so hiding <em>Weight</em> here leaves it exactly as it was on the other page.</li>
<li>Reach for this pattern when you need full control over the <code><QuickGrid></code> element and its attributes.</li>
<li>Want a toolbar, quick search and pagination without writing markup? See <a href="users-grid-wrapper">QuickGridWrapper</a>, which uses the very same column configuration.</li>
</ul>
</ExampleInfo>
<div class="my-3">
<ColumnSelector ColumnManager="_columnManager" SelectionChanged="SelectionChangedAsync" />
</div>
<QuickGrid @ref="_grid" Items="@_items.AsQueryable()" Class="table table-sm table-index table-striped small table-fit table-thead-sticky mb-0" Theme="twentyAI">
@QuickGridColumns.Columns(_columnManager)
</QuickGrid>
@code {
private List<UserDto> _items = new();
private ColumnManager<UserDto> _columnManager = new();
private QuickGrid<UserDto>? _grid;
protected override void OnInitialized()
{
_columnManager.AddIndexColumn();
_columnManager.Add(new() { Property = p => p.Id });
_columnManager.AddSimple(p => p.Name, fullTitle: "Name");
_columnManager.AddRange(SharedUserColumnManager.Instance.Columns);
_columnManager.AddToggleColumn(p => p.RemoteWorking, "Remote", fullTitle: "Remote Working", onChange: ToggleChange);
_columnManager.AddCountry();
_items = UserService.GetUsers();
}
private async Task SelectionChangedAsync()
{
if (_grid is null) return;
await _grid.RefreshDataAsync();
}
private async Task ToggleChange(UserDto user)
{
user.RemoteWorking = !user.RemoteWorking;
await Task.CompletedTask;
StateHasChanged();
}
}
<ExampleNav Route="users-grid" />