Skip to content

Commit 6570642

Browse files
ArgoZhangAApuciljmay168
authored
feat(Table): add FitColumnWidthIncludeHeader parameter (#6871)
* Update auto-fit column width callback to include width Modified the OnAutoFitContentAsync callback to accept the calculated column width as a parameter in both C# and JavaScript. This allows custom logic to consider the current width when determining the final column width, improving flexibility for auto-fit scenarios. Co-Authored-By: ljmay168 <[email protected]> * Update OnAutoFitContentAsync to accept calcWidth parameter Modified the UnitTest * Update TableTest.cs 修改 单元测试宽度计算 Signed-off-by: AApuci <[email protected]> * revert: 撤销与本 PR 无关改动 * revert: 撤销更改 * test: 代码格式化 * refactor: 弃用 OnAutoFitContentAsync 改用 OnAutoFitColumnWidthCallback 回调方法 * refactor: 更改方法名称 * feat: 增加 FitColumnWidthIncludeHeader 参数 * feat: 传递 FitColumnWidthIncludeHeader 参数到 js * refactor: 增加逻辑 * chore: bump version 9.11.2-beta03 --------- Signed-off-by: AApuci <[email protected]> Co-authored-by: AApuci <[email protected]> Co-authored-by: ljmay168 <[email protected]> Co-authored-by: AApuci <[email protected]>
1 parent b9a132b commit 6570642

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

src/BootstrapBlazor/BootstrapBlazor.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Razor">
22

33
<PropertyGroup>
4-
<Version>9.11.2-beta02</Version>
4+
<Version>9.11.2-beta03</Version>
55
</PropertyGroup>
66

77
<ItemGroup>

src/BootstrapBlazor/Components/Table/Table.razor.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,6 +1066,7 @@ private async Task OnTableRenderAsync(bool firstRender)
10661066
{
10671067
DragColumnCallback = nameof(DragColumnCallback),
10681068
AutoFitColumnWidthCallback = OnAutoFitColumnWidthCallback == null ? null : nameof(AutoFitColumnWidthCallback),
1069+
FitColumnWidthIncludeHeader,
10691070
ResizeColumnCallback = OnResizeColumnAsync != null ? nameof(ResizeColumnCallback) : null,
10701071
ColumnMinWidth = ColumnMinWidth ?? Options.CurrentValue.TableSettings.ColumnMinWidth,
10711072
ScrollWidth = ActualScrollWidth,
@@ -1598,6 +1599,12 @@ private async Task OnContextMenu(MouseEventArgs e, TItem item)
15981599
[Parameter]
15991600
public Func<string, float, Task<float>>? OnAutoFitColumnWidthCallback { get; set; }
16001601

1602+
/// <summary>
1603+
/// 获得/设置 列宽自适应时是否包含表头 默认 false
1604+
/// </summary>
1605+
[Parameter]
1606+
public bool FitColumnWidthIncludeHeader { get; set; }
1607+
16011608
/// <summary>
16021609
/// 列宽自适应方法
16031610
/// </summary>

src/BootstrapBlazor/Components/Table/Table.razor.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,12 @@ const autoFitColumnWidth = async (table, col) => {
742742
maxWidth = Math.max(maxWidth, calcCellWidth(cell));
743743
});
744744

745+
if (table.options.fitColumnWidthIncludeHeader) {
746+
const th = col.closest('th');
747+
const span = th.querySelector('.table-cell');
748+
maxWidth = Math.max(maxWidth, calcCellWidth(span));
749+
}
750+
745751
if (table.options.autoFitColumnWidthCallback !== null) {
746752
const widthValue = await table.invoke.invokeMethodAsync(table.options.autoFitColumnWidthCallback, field, maxWidth);
747753
if (widthValue > 0) {

0 commit comments

Comments
 (0)