diff --git a/src/admin/Bootstrap.Admin/Components/TableBase.cs b/src/admin/Bootstrap.Admin/Components/TableBase.cs
index 1012cb72..87516a25 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;
@@ -66,6 +67,12 @@ namespace Bootstrap.Admin.Components
[Parameter]
public bool FixedHeader { get; set; }
+ ///
+ /// 获得 IJSRuntime 实例
+ ///
+ [Inject]
+ protected IJSRuntime? JSRuntime { get; set; }
+
///
/// 获得/设置 是否自适应高度 默认为 false 不自适应高度
///
@@ -203,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());
+ }
+ }
+
///
/// 点击页码调用此方法
///
@@ -365,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 8bfa3dde..1caf030a 100644
--- a/src/admin/Bootstrap.Admin/Extensions/JSRuntimeExtensions.cs
+++ b/src/admin/Bootstrap.Admin/Extensions/JSRuntimeExtensions.cs
@@ -97,5 +97,10 @@ 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) => jSRuntime.InvokeVoidAsync("$.initTable", id);
}
}
diff --git a/src/admin/Bootstrap.Admin/Pages/Admin/Groups.razor b/src/admin/Bootstrap.Admin/Pages/Admin/Groups.razor
index 2a4f3018..1c15e147 100644
--- a/src/admin/Bootstrap.Admin/Pages/Admin/Groups.razor
+++ b/src/admin/Bootstrap.Admin/Pages/Admin/Groups.razor
@@ -1,6 +1,6 @@
@inherits GroupsBase
-
+
diff --git a/src/admin/Bootstrap.Admin/Pages/Admin/Menus.razor b/src/admin/Bootstrap.Admin/Pages/Admin/Menus.razor
index a3100691..0fafa7d7 100644
--- a/src/admin/Bootstrap.Admin/Pages/Admin/Menus.razor
+++ b/src/admin/Bootstrap.Admin/Pages/Admin/Menus.razor
@@ -1,6 +1,6 @@
@inherits MenusBase
-
+
diff --git a/src/admin/Bootstrap.Admin/Pages/Admin/Roles.razor b/src/admin/Bootstrap.Admin/Pages/Admin/Roles.razor
index 1e40ba7b..cb1851c4 100644
--- a/src/admin/Bootstrap.Admin/Pages/Admin/Roles.razor
+++ b/src/admin/Bootstrap.Admin/Pages/Admin/Roles.razor
@@ -1,6 +1,6 @@
@inherits RolesBase
-
+
diff --git a/src/admin/Bootstrap.Admin/Pages/Admin/Users.razor b/src/admin/Bootstrap.Admin/Pages/Admin/Users.razor
index 2b3677fc..a171efe4 100644
--- a/src/admin/Bootstrap.Admin/Pages/Admin/Users.razor
+++ b/src/admin/Bootstrap.Admin/Pages/Admin/Users.razor
@@ -1,6 +1,6 @@
@inherits UsersBase
-
+
diff --git a/src/admin/Bootstrap.Admin/Shared/Table.razor b/src/admin/Bootstrap.Admin/Shared/Table.razor
index 11c67c91..424a7cac 100644
--- a/src/admin/Bootstrap.Admin/Shared/Table.razor
+++ b/src/admin/Bootstrap.Admin/Shared/Table.razor
@@ -37,7 +37,7 @@
-
+
@if (ShowCheckbox)
diff --git a/src/admin/Bootstrap.Admin/wwwroot/css/blazor.css b/src/admin/Bootstrap.Admin/wwwroot/css/blazor.css
index 94372a89..945d5da1 100644
--- a/src/admin/Bootstrap.Admin/wwwroot/css/blazor.css
+++ b/src/admin/Bootstrap.Admin/wwwroot/css/blazor.css
@@ -136,6 +136,10 @@ nav .dropdown .nav-link-close.dropdown-toggle:after {
height: 300px;
}
+ .bootstrap-table .fixed-table-body table {
+ margin-top: -38px;
+ }
+
.bootstrap-table .fixed-table-body thead th, .bootstrap-table .fixed-table-header thead th {
border-bottom: 1px solid #dee2e6;
}
diff --git a/src/admin/Bootstrap.Admin/wwwroot/js/ba.blazor.js b/src/admin/Bootstrap.Admin/wwwroot/js/ba.blazor.js
index 9e13acf5..4a21e4b3 100644
--- a/src/admin/Bootstrap.Admin/wwwroot/js/ba.blazor.js
+++ b/src/admin/Bootstrap.Admin/wwwroot/js/ba.blazor.js
@@ -140,10 +140,34 @@
var $tabContent = $('section .tab-content');
if (showCardTitle) $tabContent.removeClass('no-card-header');
else $tabContent.addClass('no-card-header');
+ },
+ initTable: function (id) {
+ var $table = $('#' + id);
+ var $tableContainer = $table.parents('.table-wrapper');
+ var $tableHeader = $tableContainer.find('.fixed-table-header table');
- var $table = $(".bootstrap-table");
- if (fixedTableHeader) $table.attr('data-header', 'fixed');
- else $table.attr('data-header', 'scroll');
+ // resetWidth()
+ var $heads = $tableHeader.find('th');
+ var resetWidth = function () {
+ $table.find('th').each(function (index, element) {
+ var header = $heads.get(index);
+ $(header).width($(element).width());
+ });
+ }
+ resetWidth();
+
+ // modify scroll
+ $table.parent().overlayScrollbars({
+ className: 'os-theme-dark',
+ scrollbars: {
+ autoHide: 'leave',
+ autoHideDelay: 100
+ }
+ }).removeClass('d-none');
+
+ $(window).on('resize', function () {
+ resetWidth();
+ });
}
});