|
7 | 7 |
|
8 | 8 | <h4>@Localizer["TablesDynamicDescription"]</h4> |
9 | 9 |
|
| 10 | +<p class="code-label">@Localizer["TablesDynamicNoteTitle"]</p> |
| 11 | +<p>@((MarkupString)Localizer["TablesDynamicNoteP1"].Value)</p> |
| 12 | +<p>@((MarkupString)Localizer["TablesDynamicNoteP2"].Value)</p> |
| 13 | +<p>@((MarkupString)Localizer["TablesDynamicNoteP3"].Value)</p> |
| 14 | +<Pre>private void CreatePageDataContext() |
| 15 | +{ |
| 16 | + _dataTableDynamicContext4 = new DataTableDynamicContext(_pageDataTable, (context, col) => |
| 17 | + { |
| 18 | + var propertyName = col.GetFieldName(); |
| 19 | + }) |
| 20 | + { |
| 21 | + UseCache = false |
| 22 | + }; |
| 23 | +} |
| 24 | + |
| 25 | +private void UpdatePageDataContext() |
| 26 | +{ |
| 27 | + var table = _dataTableDynamicContext4!.DataTable; |
| 28 | + table.Rows.Clear(); |
| 29 | + |
| 30 | + foreach (var f in _pageData.Skip((_pageIndex - 1) * _pageItems).Take(_pageItems).ToList()) |
| 31 | + { |
| 32 | + table.Rows.Add(f.Id, f.DateTime, f.Name, f.Count); |
| 33 | + } |
| 34 | + |
| 35 | + table.AcceptChanges(); |
| 36 | +}</Pre> |
| 37 | + |
10 | 38 | <DemoBlock Title="@Localizer["TablesDynamicDataTableTitle"]" |
11 | 39 | Introduction="@Localizer["TablesDynamicDataTableIntro"]" |
12 | 40 | Name="DataTable"> |
13 | | - <Table TItem="DynamicObject" DynamicContext="DataTableDynamicContext" IsFixedHeader="true" Height="300" /> |
| 41 | + <Table TItem="DynamicObject" DynamicContext="_dataTableDynamicContext1" IsFixedHeader="true" Height="300"></Table> |
14 | 42 | </DemoBlock> |
15 | 43 |
|
16 | 44 | <DemoBlock Title="@Localizer["TablesDynamicEditTitle"]" |
17 | 45 | Introduction="@Localizer["TablesDynamicEditIntro"]" |
18 | 46 | Name="Edit"> |
19 | 47 | <section ignore>@((MarkupString)Localizer["TablesDynamicEditDescription"].Value)</section> |
20 | | - <Table TItem="DynamicObject" DynamicContext="DataTableDynamicContext" ModelEqualityComparer="ModelEqualityComparer" |
21 | | - IsMultipleSelect="true" IsBordered="true" IsStriped="true" @bind-SelectedRows="SelectedItems" IsKeepSelectedRowAfterAdd="true" |
22 | | - ShowToolbar="true" ShowExtendButtons="true" /> |
| 48 | + <Table TItem="DynamicObject" DynamicContext="_dataTableDynamicContext2" ModelEqualityComparer="ModelEqualityComparer" |
| 49 | + IsMultipleSelect="true" IsBordered="true" IsStriped="true" @bind-SelectedRows="_selectedItems" IsKeepSelectedRowAfterAdd="true" |
| 50 | + ShowToolbar="true" ShowExtendButtons="true"></Table> |
23 | 51 | <div class="mt-3"> |
24 | | - @foreach (var item in SelectedItems) |
| 52 | + @foreach (var item in _selectedItems) |
25 | 53 | { |
26 | 54 | <div>@item.GetValue(nameof(Foo.Name))</div> |
27 | 55 | } |
|
31 | 59 | <DemoBlock Title="@Localizer["TablesDynamicDynamicColTitle"]" |
32 | 60 | Introduction="@Localizer["TablesDynamicDynamicColIntro"]" |
33 | 61 | Name="DynamicCol"> |
34 | | - <Table TItem="DynamicObject" DynamicContext="DataTableDynamicContext" ModelEqualityComparer="ModelEqualityComparer" |
| 62 | + <Table TItem="DynamicObject" DynamicContext="_dataTableDynamicContext3" ModelEqualityComparer="ModelEqualityComparer" |
35 | 63 | IsMultipleSelect="true" IsBordered="true" IsStriped="true" |
36 | 64 | ShowToolbar="true" ShowExtendButtons="true"> |
37 | 65 | <TableToolbarTemplate> |
38 | | - <TableToolbarButton Color="Color.Info" Icon="fa-fw fa-solid fa-circle-plus" Text="@ButtonAddColumnText" OnClick="OnAddColumn" /> |
39 | | - <TableToolbarButton Color="Color.Secondary" Icon="fa-fw fa-solid fa-circle-minus" Text="@ButtonRemoveColumnText" OnClick="OnRemoveColumn" /> |
| 66 | + <TableToolbarButton Color="Color.Info" Icon="fa-fw fa-solid fa-circle-plus" Text="@_buttonAddColumnText" |
| 67 | + OnClick="@OnAddColumn"> |
| 68 | + </TableToolbarButton> |
| 69 | + <TableToolbarButton Color="Color.Secondary" Icon="fa-fw fa-solid fa-circle-minus" Text="@_buttonRemoveColumnText" |
| 70 | + OnClick="@OnRemoveColumn"> |
| 71 | + </TableToolbarButton> |
40 | 72 | </TableToolbarTemplate> |
41 | 73 | </Table> |
42 | 74 | </DemoBlock> |
43 | 75 |
|
44 | 76 | <DemoBlock Title="@Localizer["TablesDynamicPageTitle"]" |
45 | 77 | Introduction="@Localizer["TablesDynamicPageIntro"]" |
46 | 78 | Name="Pagination"> |
47 | | - <Table TItem="DynamicObject" DynamicContext="DataTablePageDynamicContext" /> |
48 | | - <Pagination PageCount="@PageCount" PageIndex="@PageIndex" OnPageLinkClick="@OnPageLinkClick" class="mt-3" /> |
| 79 | + <Table TItem="DynamicObject" DynamicContext="_dataTableDynamicContext4"></Table> |
| 80 | + <Pagination PageCount="@_pageCount" PageIndex="@_pageIndex" OnPageLinkClick="@OnPageLinkClick" class="mt-3"></Pagination> |
49 | 81 | </DemoBlock> |
0 commit comments