diff --git a/src/WebAssembly/BootstrapBlazorApp.WebAssembly/Pages/TableDemo.razor b/src/WebAssembly/BootstrapBlazorApp.WebAssembly/Pages/TableDemo.razor index c68d879..f5008b3 100644 --- a/src/WebAssembly/BootstrapBlazorApp.WebAssembly/Pages/TableDemo.razor +++ b/src/WebAssembly/BootstrapBlazorApp.WebAssembly/Pages/TableDemo.razor @@ -1,13 +1,13 @@ @page "/table" @attribute [TabItemOption(Text = "Table")] -Table -

Table - 固定标签页

+Table - +
diff --git a/src/WebAssembly/BootstrapBlazorApp.WebAssembly/Pages/TableDemo.razor.cs b/src/WebAssembly/BootstrapBlazorApp.WebAssembly/Pages/TableDemo.razor.cs index 1dfe00b..9c3a926 100644 --- a/src/WebAssembly/BootstrapBlazorApp.WebAssembly/Pages/TableDemo.razor.cs +++ b/src/WebAssembly/BootstrapBlazorApp.WebAssembly/Pages/TableDemo.razor.cs @@ -24,4 +24,91 @@ public partial class TableDemo : ComponentBase /// /// private static IEnumerable PageItemsSource => new int[] { 20, 40 }; + + [NotNull] + private List? Items { get; set; } + + /// + /// 查询操作方法 + /// + /// + /// + private Task> OnQueryAsync(QueryPageOptions options) + { + // 此处代码实战中不可用,仅仅为演示而写防止数据全部被删除 + if (Items == null || Items.Count == 0) + { + Items = Foo.GenerateFoo(Localizer); + } + + var items = Items.Where(options.ToFilterFunc()); + // 排序 + var isSorted = false; + if (!string.IsNullOrEmpty(options.SortName)) + { + items = items.Sort(options.SortName, options.SortOrder); + isSorted = true; + } + + var total = items.Count(); + return Task.FromResult(new QueryData() + { + Items = items.Skip((options.PageIndex - 1) * options.PageItems).Take(options.PageItems).ToList(), + TotalCount = total, + IsFiltered = true, + IsSorted = isSorted, + IsSearch = true + }); + } + + private Task OnSaveAsync(Foo foo, ItemChangedType changedType) + { + var ret = false; + if (changedType == ItemChangedType.Add) + { + var id = Items.Count + 1; + while (Items.Find(item => item.Id == id) != null) + { + id++; + } + var item = new Foo() + { + Id = id, + Name = foo.Name, + Address = foo.Address, + Complete = foo.Complete, + Count = foo.Count, + DateTime = foo.DateTime, + Education = foo.Education, + Hobby = foo.Hobby + }; + Items.Add(item); + } + else + { + var f = Items.Find(i => i.Id == foo.Id); + if (f != null) + { + f.Name = foo.Name; + f.Address = foo.Address; + f.Complete = foo.Complete; + f.Count = foo.Count; + f.DateTime = foo.DateTime; + f.Education = foo.Education; + f.Hobby = foo.Hobby; + } + } + ret = true; + return Task.FromResult(ret); + } + + private Task OnDeleteAsync(IEnumerable foos) + { + foreach (var foo in foos) + { + Items.Remove(foo); + } + + return Task.FromResult(true); + } } diff --git a/src/WebAssembly/BootstrapBlazorApp.WebAssembly/Pages/Users.razor b/src/WebAssembly/BootstrapBlazorApp.WebAssembly/Pages/Users.razor index 3f2e097..213e973 100644 --- a/src/WebAssembly/BootstrapBlazorApp.WebAssembly/Pages/Users.razor +++ b/src/WebAssembly/BootstrapBlazorApp.WebAssembly/Pages/Users.razor @@ -7,7 +7,8 @@

只读数据 - 更改每页显示数量体验固定表头功能

-
@@ -26,9 +27,9 @@ - + - +