Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Table): can't resize column when use dynamic data #2367

Merged
merged 5 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/BootstrapBlazor/BootstrapBlazor.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<Version>7.12.2-beta01</Version>
<Version>7.12.2-beta02</Version>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">
Expand Down
3 changes: 3 additions & 0 deletions src/BootstrapBlazor/Components/Table/Table.razor.Toolbar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,9 @@ private void ResetDynamicContext()
InternalResetVisibleColumns(Columns.Select(i => new ColumnVisibleItem(i.GetFieldName(), i.Visible)));

QueryDynamicItems(DynamicContext);

// 重新绑定列拖拽
_bindResizeColumn = true;
}
}

Expand Down
12 changes: 10 additions & 2 deletions src/BootstrapBlazor/Components/Table/Table.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,10 @@ namespace BootstrapBlazor.Components;
private static string? GetColWidthString(int? width) => width.HasValue ? $"width: {width.Value}px;" : null;

/// <summary>
/// 获得/设置 滚动条宽度 默认为 7
/// 获得/设置 滚动条宽度 默认为 6
/// </summary>
[Parameter]
public int ScrollWidth { get; set; } = 7;
public int ScrollWidth { get; set; } = 6;

private string ScrollWidthString => $"width: {ScrollWidth}px;";

Expand Down Expand Up @@ -715,6 +715,8 @@ private void OnInitParameters()
/// </summary>
protected CancellationTokenSource? AutoRefreshCancelTokenSource { get; set; }

private bool _bindResizeColumn;

/// <summary>
/// OnParametersSet 方法
/// </summary>
Expand Down Expand Up @@ -800,6 +802,12 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
await InvokeVoidAsync("resetColumn", Id);
}

if (_bindResizeColumn)
{
_bindResizeColumn = false;
await InvokeVoidAsync("bindResizeColumn", Id);
}

if (UpdateSortTooltip)
{
UpdateSortTooltip = false;
Expand Down
15 changes: 13 additions & 2 deletions src/BootstrapBlazor/Components/Table/Table.razor.js
Original file line number Diff line number Diff line change
Expand Up @@ -515,8 +515,19 @@ export function reset(id) {

export function resetColumn(id) {
const table = Data.get(id)
setResizeListener(table)
resetTableWidth(table)
if (table) {
setResizeListener(table)
resetTableWidth(table)
}
}

export function bindResizeColumn(id) {
const table = Data.get(id)
if (table) {
if (table.isResizeColumn) {
setResizeListener(table)
}
}
}

export function sort(id) {
Expand Down
8 changes: 8 additions & 0 deletions src/BootstrapBlazor/Components/Table/Table.razor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
--bb-table-copy-column-margin-right: .5rem;
--bb-table-column-fixed-border-color: #dee2e6;
--bb-loader-bg: #f8f9fa;
--bb-table-column-resizer-color: #ddd;
--bb-table-column-resizer-hover-color: #ddd;
position: relative;
height: 100%;
}
Expand Down Expand Up @@ -582,6 +584,12 @@ tr.active:not(.is-edit):hover {
right: 0;
bottom: 0;
cursor: col-resize;
border-right: 1px solid var(--bb-table-column-resizer-color);
transition: background-color .3s linear;

&:hover {
background-color: var(--bb-table-column-resizer-hover-color);
}
}

.table-resize .border-resize {
Expand Down

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions src/BootstrapBlazor/wwwroot/scss/bootstrap.blazor.css
Original file line number Diff line number Diff line change
Expand Up @@ -6149,6 +6149,8 @@ body:before {
--bb-table-copy-column-margin-right: .5rem;
--bb-table-column-fixed-border-color: #dee2e6;
--bb-loader-bg: #f8f9fa;
--bb-table-column-resizer-color: #ddd;
--bb-table-column-resizer-hover-color: #ddd;
position: relative;
height: 100%;
}
Expand Down Expand Up @@ -6712,6 +6714,11 @@ tr.active:not(.is-edit):hover {
right: 0;
bottom: 0;
cursor: col-resize;
border-right: 1px solid var(--bb-table-column-resizer-color);
transition: background-color 0.3s linear;
}
.col-resizer:hover {
background-color: var(--bb-table-column-resizer-hover-color);
}

.table-resize .border-resize {
Expand Down
2 changes: 1 addition & 1 deletion src/BootstrapBlazor/wwwroot/scss/bootstrap.blazor.min.css

Large diffs are not rendered by default.