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 @@
-
+
-
+
@value.Value %
diff --git a/src/WebAssembly/BootstrapBlazorApp.WebAssembly/Pages/Users.razor.cs b/src/WebAssembly/BootstrapBlazorApp.WebAssembly/Pages/Users.razor.cs
index f49b6cd..0eeb4ed 100644
--- a/src/WebAssembly/BootstrapBlazorApp.WebAssembly/Pages/Users.razor.cs
+++ b/src/WebAssembly/BootstrapBlazorApp.WebAssembly/Pages/Users.razor.cs
@@ -34,57 +34,23 @@ public partial class Users
};
[NotNull]
- private IEnumerable
? Items { get; set; }
-
- private static readonly ConcurrentDictionary, string, SortOrder, IEnumerable>> SortLambdaCache = new();
+ private List? Items { get; set; }
private Task> OnQueryAsync(QueryPageOptions options)
{
// 此处代码实战中不可用,仅仅为演示而写防止数据全部被删除
- if (Items == null || !Items.Any())
- {
- Items = Foo.GenerateFoo(Localizer, 23).ToList();
- }
-
- var items = Items;
- var isSearched = false;
- // 处理高级查询
- if (options.SearchModel is Foo model)
+ if (Items == null || Items.Count == 0)
{
- if (!string.IsNullOrEmpty(model.Name))
- {
- items = items.Where(item => item.Name?.Contains(model.Name, StringComparison.OrdinalIgnoreCase) ?? false);
- }
-
- if (!string.IsNullOrEmpty(model.Address))
- {
- items = items.Where(item => item.Address?.Contains(model.Address, StringComparison.OrdinalIgnoreCase) ?? false);
- }
-
- isSearched = !string.IsNullOrEmpty(model.Name) || !string.IsNullOrEmpty(model.Address);
+ Items = Foo.GenerateFoo(Localizer, 23);
}
- if (options.Searches.Any())
- {
- // 针对 SearchText 进行模糊查询
- items = items.Where(options.Searches.GetFilterFunc(FilterLogic.Or));
- }
-
- // 过滤
- var isFiltered = false;
- if (options.Filters.Count != 0)
- {
- items = items.Where(options.Filters.GetFilterFunc());
- isFiltered = true;
- }
+ var items = Items.Where(options.ToFilterFunc());
// 排序
var isSorted = false;
if (!string.IsNullOrEmpty(options.SortName))
{
- // 外部未进行排序,内部自动进行排序处理
- var invoker = SortLambdaCache.GetOrAdd(typeof(Foo), key => LambdaExtensions.GetSortLambda().Compile());
- items = invoker(items, options.SortName, options.SortOrder);
+ items = items.Sort(options.SortName, options.SortOrder);
isSorted = true;
}
@@ -94,9 +60,9 @@ private Task> OnQueryAsync(QueryPageOptions options)
{
Items = items.Skip((options.PageIndex - 1) * options.PageItems).Take(options.PageItems).ToList(),
TotalCount = total,
- IsFiltered = isFiltered,
+ IsFiltered = true,
IsSorted = isSorted,
- IsSearch = isSearched
+ IsSearch = true
});
}
}
diff --git a/src/WebAssembly/BootstrapBlazorApp.WebAssembly/Program.cs b/src/WebAssembly/BootstrapBlazorApp.WebAssembly/Program.cs
index 27b85ae..0afcedc 100644
--- a/src/WebAssembly/BootstrapBlazorApp.WebAssembly/Program.cs
+++ b/src/WebAssembly/BootstrapBlazorApp.WebAssembly/Program.cs
@@ -1,5 +1,4 @@
using BootstrapBlazorApp.WebAssembly;
-using BootstrapBlazorApp.WebAssembly.Services;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
@@ -15,7 +14,4 @@
options.DefaultCultureInfo = "zh-CN";
});
-// 增加 Table 数据服务操作类
-builder.Services.AddTableDemoDataService();
-
await builder.Build().RunAsync();
diff --git a/src/WebAssembly/BootstrapBlazorApp.WebAssembly/Services/TableDemoDataServiceCollectionExtensions.cs b/src/WebAssembly/BootstrapBlazorApp.WebAssembly/Services/TableDemoDataServiceCollectionExtensions.cs
deleted file mode 100644
index e909c07..0000000
--- a/src/WebAssembly/BootstrapBlazorApp.WebAssembly/Services/TableDemoDataServiceCollectionExtensions.cs
+++ /dev/null
@@ -1,161 +0,0 @@
-using BootstrapBlazor.Components;
-using BootstrapBlazorApp.WebAssembly.Data;
-using Microsoft.Extensions.Localization;
-using System.Collections.Concurrent;
-using System.Diagnostics.CodeAnalysis;
-
-namespace BootstrapBlazorApp.WebAssembly.Services;
-
-///
-/// BootstrapBlazor 服务扩展类
-///
-public static class TableDemoDataServiceCollectionExtensions
-{
- ///
- /// 增加 PetaPoco 数据库操作服务
- ///
- ///
- ///
- public static IServiceCollection AddTableDemoDataService(this IServiceCollection services)
- {
- services.AddScoped(typeof(IDataService<>), typeof(TableDemoDataService<>));
- return services;
- }
-}
-
-///
-/// 演示网站示例数据注入服务实现类
-///
-internal class TableDemoDataService(IStringLocalizer localizer) : DataServiceBase where TModel : class, new()
-{
- private static readonly ConcurrentDictionary, string, SortOrder, IEnumerable>> SortLambdaCache = new();
-
- [NotNull]
- private List? Items { get; set; }
-
- ///
- /// 查询操作方法
- ///
- ///
- ///
- public override Task> QueryAsync(QueryPageOptions options)
- {
- // 此处代码实战中不可用,仅仅为演示而写防止数据全部被删除
- if (Items == null || Items.Count == 0)
- {
- Items = Foo.GenerateFoo(localizer).Cast().ToList();
- }
-
- var items = Items.AsEnumerable();
- var isSearched = false;
- // 处理高级查询
- if (options.SearchModel is Foo model)
- {
- if (!string.IsNullOrEmpty(model.Name))
- {
- items = items.Cast().Where(item => item.Name?.Contains(model.Name, StringComparison.OrdinalIgnoreCase) ?? false).Cast();
- }
-
- if (!string.IsNullOrEmpty(model.Address))
- {
- items = items.Cast().Where(item => item.Address?.Contains(model.Address, StringComparison.OrdinalIgnoreCase) ?? false).Cast();
- }
-
- isSearched = !string.IsNullOrEmpty(model.Name) || !string.IsNullOrEmpty(model.Address);
- }
-
- if (options.Searches.Count != 0)
- {
- // 针对 SearchText 进行模糊查询
- items = items.Where(options.Searches.GetFilterFunc(FilterLogic.Or));
- }
-
- // 过滤
- var isFiltered = false;
- if (options.Filters.Count != 0)
- {
- items = items.Where(options.Filters.GetFilterFunc());
- isFiltered = true;
- }
-
- // 排序
- var isSorted = false;
- if (!string.IsNullOrEmpty(options.SortName))
- {
- // 外部未进行排序,内部自动进行排序处理
- var invoker = SortLambdaCache.GetOrAdd(typeof(Foo), key => LambdaExtensions.GetSortLambda().Compile());
- items = invoker(items, 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 = isFiltered,
- IsSorted = isSorted,
- IsSearch = isSearched
- });
- }
-
- ///
- ///
- ///
- ///
- ///
- public override Task SaveAsync(TModel model, ItemChangedType changedType)
- {
- var ret = false;
- if (model is Foo foo)
- {
- if (changedType == ItemChangedType.Add)
- {
- var id = Items.Count + 1;
- while (Items.FirstOrDefault(item => (item as Foo)!.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
- } as TModel;
- Items.Add(item!);
- }
- else
- {
- var f = Items.OfType().FirstOrDefault(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);
- }
-
- public override Task DeleteAsync(IEnumerable models)
- {
- foreach (var model in models)
- {
- Items.Remove(model);
- }
-
- return base.DeleteAsync(models);
- }
-}
diff --git a/src/WebAssembly/BootstrapBlazorApp.WebAssembly/wwwroot/css/app.css b/src/WebAssembly/BootstrapBlazorApp.WebAssembly/wwwroot/css/app.css
index 7f70875..1ed7836 100644
--- a/src/WebAssembly/BootstrapBlazorApp.WebAssembly/wwwroot/css/app.css
+++ b/src/WebAssembly/BootstrapBlazorApp.WebAssembly/wwwroot/css/app.css
@@ -117,10 +117,6 @@
color: #c0c4cc;
}
-.table-demo {
- height: calc(100% - 56px);
-}
-
.table-users-demo {
height: calc(100vh - 162px);
}