Skip to content
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
9 changes: 9 additions & 0 deletions src/BootstrapBlazor/Components/Table/Table.razor.Checkbox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ protected async Task OnCheck(CheckboxState state, TItem val)
/// </summary>
private bool _resetColumns;

/// <summary>
/// 是否重置列拖拽事件 <see cref="OnAfterRenderAsync(bool)"/> 方法中重置为 false
/// </summary>
private bool _resetColDragListener;

/// <summary>
/// 获得/设置 列改变显示状态回调方法
/// </summary>
Expand All @@ -155,6 +160,10 @@ private async Task OnToggleColumnVisible(string columnName, bool visible)
{
_resetColumns = true;
}
if (AllowDragColumn && visible)
{
_resetColDragListener = true;
}
if (!string.IsNullOrEmpty(ClientTableName))
{
await InvokeVoidAsync("saveColumnList", ClientTableName, _visibleColumns);
Expand Down
6 changes: 6 additions & 0 deletions src/BootstrapBlazor/Components/Table/Table.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,12 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
await InvokeVoidAsync("resetColumn", Id);
}

if (_resetColDragListener)
{
_resetColDragListener= false;
Copy link

Copilot AI Nov 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space after assignment operator. Should be _resetColDragListener = false; instead of _resetColDragListener= false;

Suggested change
_resetColDragListener= false;
_resetColDragListener = false;

Copilot uses AI. Check for mistakes.
await InvokeVoidAsync("resetColDragListener", Id);
}

if (_bindResizeColumn)
{
_bindResizeColumn = false;
Expand Down
11 changes: 10 additions & 1 deletion src/BootstrapBlazor/Components/Table/Table.razor.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { getResponsive } from '../../modules/responsive.js'
export { getResponsive } from '../../modules/responsive.js'
import { copy, drag, getDescribedElement, getOuterHeight, getWidth, isVisible } from '../../modules/utility.js'
import '../../modules/browser.js'
import Data from '../../modules/data.js'
Expand Down Expand Up @@ -180,6 +180,13 @@ export function resetColumn(id) {
}
}

export function resetColDragListener(id) {
const table = Data.get(id)
if (table) {
setDraggable(table)
}
}

export function bindResizeColumn(id) {
const table = Data.get(id)
if (table) {
Expand Down Expand Up @@ -924,6 +931,8 @@ const setDraggable = table => {
let index = 0
table.dragColumns = [...table.tables[0].querySelectorAll('thead > tr > th')].filter(i => i.draggable)
table.dragColumns.forEach(col => {
disposeDragColumns(col);
Copy link

Copilot AI Nov 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The disposeDragColumns function expects an array of columns (as seen on line 983 where it uses (columns ?? []).forEach(...)), but here it's being called with a single column element col. This should be wrapped in an array: disposeDragColumns([col]); or the function should be refactored to handle both single elements and arrays.

Suggested change
disposeDragColumns(col);
disposeColumnDrag([col]);

Copilot uses AI. Check for mistakes.

EventHandler.on(col, 'dragstart', e => {
col.parentNode.classList.add('table-dragging')
col.classList.add('table-drag')
Expand Down
34 changes: 26 additions & 8 deletions test/UnitTest/Components/TableTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8476,6 +8476,8 @@ public async Task AllowDragColumn_Ok()
{
pb.Add(a => a.RenderMode, TableRenderMode.Table);
pb.Add(a => a.AllowDragColumn, true);
pb.Add(a => a.ShowToolbar, true);
pb.Add(a => a.ShowColumnList, true);
pb.Add(a => a.ClientTableName, "table-unit-test");
pb.Add(a => a.OnQueryAsync, OnQueryAsync(localizer));
pb.Add(a => a.OnDragColumnEndAsync, (fieldName, columns) =>
Expand All @@ -8490,9 +8492,14 @@ public async Task AllowDragColumn_Ok()
builder.AddAttribute(2, "FieldExpression", Utility.GenerateValueExpression(foo, "Name", typeof(string)));
builder.CloseComponent();

builder.OpenComponent<TableColumn<Foo, string>>(0);
builder.AddAttribute(3, "Field", "Address");
builder.AddAttribute(4, "FieldExpression", Utility.GenerateValueExpression(foo, "Address", typeof(string)));
builder.OpenComponent<TableColumn<Foo, string>>(3);
builder.AddAttribute(4, "Field", "Address");
builder.AddAttribute(5, "FieldExpression", Utility.GenerateValueExpression(foo, "Address", typeof(string)));
builder.CloseComponent();

builder.OpenComponent<TableColumn<Foo, int>>(6);
builder.AddAttribute(7, "Field", foo.Count);
Copy link

Copilot AI Nov 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Field attribute should be set to the field name as a string "Count", not the field value foo.Count. This is inconsistent with the pattern used on lines 8491 and 8496 where field names are passed as strings ("Name", "Address").

Suggested change
builder.AddAttribute(7, "Field", foo.Count);
builder.AddAttribute(7, "Field", "Count");

Copilot uses AI. Check for mistakes.
builder.AddAttribute(8, "FieldExpression", Utility.GenerateValueExpression(foo, "Count", typeof(int)));
builder.CloseComponent();
});
});
Expand All @@ -8502,17 +8509,28 @@ public async Task AllowDragColumn_Ok()
await cut.InvokeAsync(async () =>
{
await table.Instance.DragColumnCallback(1, 0);
Assert.Equal("Address", name);
});
Assert.Equal("Address", name);

var columns = cut.FindAll("th");
Assert.Contains("地址", columns[0].InnerHtml);
Assert.Contains("姓名", columns[1].InnerHtml);

await cut.InvokeAsync(async () =>
{
var columns = cut.FindAll("th");
Assert.Contains("地址", columns[0].InnerHtml);
Assert.Contains("姓名", columns[1].InnerHtml);

await table.Instance.DragColumnCallback(2, 3);
});

// 更改可见列
var checkbox = cut.Find(".dropdown-item .form-check-input");

await cut.InvokeAsync(() => checkbox.Click());
await cut.InvokeAsync(() => checkbox.Click());

await cut.InvokeAsync(async () =>
{
await table.Instance.DragColumnCallback(3, 4);
});
}

[Fact]
Expand Down
Loading