diff --git a/src/admin/Bootstrap.Admin/Components/EditPageBase.cs b/src/admin/Bootstrap.Admin/Components/EditPageBase.cs index 185ec4c9041f61718d3efa8f5c1eb6bb201f54e3..4f8c561b50da9424f69b5efcaf290cf2eddb100d 100644 --- a/src/admin/Bootstrap.Admin/Components/EditPageBase.cs +++ b/src/admin/Bootstrap.Admin/Components/EditPageBase.cs @@ -78,6 +78,12 @@ namespace Bootstrap.Admin.Components [Parameter] public RenderFragment? EditTemplate { get; set; } + /// + /// 获得/设置 是否固定表头 默认为 false 不固定表头 + /// + [Parameter] + public bool FixedHeader { get; set; } + /// /// 获得/设置 Table 实例 /// diff --git a/src/admin/Bootstrap.Admin/Components/TableBase.cs b/src/admin/Bootstrap.Admin/Components/TableBase.cs index d5dfaa0977b407c53d634a485599be947d87af44..7f8313fe020d48ed9c5540f1f7ac632870c869bf 100644 --- a/src/admin/Bootstrap.Admin/Components/TableBase.cs +++ b/src/admin/Bootstrap.Admin/Components/TableBase.cs @@ -2,6 +2,7 @@ using Bootstrap.Admin.Shared; using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components.Forms; +using Microsoft.JSInterop; using System; using System.Collections.Generic; using System.Linq; @@ -60,6 +61,30 @@ namespace Bootstrap.Admin.Components [Parameter] public RenderFragment? TableFooter { get; set; } + /// + /// 获得/设置 是否固定表头 默认为 false 不固定表头 + /// + [Parameter] + public bool FixedHeader { get; set; } + + /// + /// 获得 IJSRuntime 实例 + /// + [Inject] + protected IJSRuntime? JSRuntime { get; set; } + + /// + /// 获得/设置 是否自适应高度 默认为 false 不自适应高度 + /// + [Parameter] + public bool AutoHeight { get; set; } + + /// + /// 获得/设置 是否显示搜索框 默认为 false 不显示搜索框 + /// + [Parameter] + public bool ShowSearch { get; set; } + /// /// 获得/设置 数据集合 /// @@ -185,6 +210,18 @@ namespace Bootstrap.Admin.Components } } + /// + /// OnInitialized 方法 + /// + protected override async System.Threading.Tasks.Task OnAfterRenderAsync(bool firstRender) + { + if (FixedHeader) + { + // 调用客户端脚本 resetWith + await JSRuntime.InitTableAsync(RetrieveId(), firstRender); + } + } + /// /// 点击页码调用此方法 /// @@ -347,5 +384,10 @@ namespace Bootstrap.Admin.Components } ShowMessage("删除数据", "删除数据" + (result ? "成功" : "失败"), result ? ToastCategory.Success : ToastCategory.Error); } + + /// + /// 获取 Id 字符串 + /// + public string RetrieveId() => $"{Id}_table"; } } diff --git a/src/admin/Bootstrap.Admin/Extensions/JSRuntimeExtensions.cs b/src/admin/Bootstrap.Admin/Extensions/JSRuntimeExtensions.cs index 8bfa3dde1b60e663abc81780b0a3875728e65082..0da6386179e2fb0d871f05c758cb7880c02fead9 100644 --- a/src/admin/Bootstrap.Admin/Extensions/JSRuntimeExtensions.cs +++ b/src/admin/Bootstrap.Admin/Extensions/JSRuntimeExtensions.cs @@ -97,5 +97,13 @@ namespace Bootstrap.Admin.Extensions /// /// public static void SetWebSettings(this IJSRuntime? jSRuntime, bool showSidebar, bool showCardTitle, bool fixedTableHeader) => jSRuntime.InvokeVoidAsync("$.setWebSettings", showSidebar, showCardTitle, fixedTableHeader); + + /// + /// 初始化 Table 组件 + /// + /// + /// + /// + public static ValueTask InitTableAsync(this IJSRuntime? jSRuntime, string id, bool firstRender) => jSRuntime.InvokeVoidAsync("$.initTable", id, firstRender); } } diff --git a/src/admin/Bootstrap.Admin/Pages/Admin/Dicts.razor b/src/admin/Bootstrap.Admin/Pages/Admin/Dicts.razor index dd8c55c3c3a9de856af53c36e02805ca0b3fbc48..94567e6ce90c9becca8cffdb839b96e61987390f 100644 --- a/src/admin/Bootstrap.Admin/Pages/Admin/Dicts.razor +++ b/src/admin/Bootstrap.Admin/Pages/Admin/Dicts.razor @@ -1,6 +1,6 @@ @inherits DictsBase - +