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
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>9.0.0-rc.2.11.3.0</Version>
<Version>9.0.0-rc.2.11.5.0</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/BootstrapBlazor/Components/Table/Table.razor
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
{
@if (ShowAddButton)
{
<TableToolbarButton TItem="TItem" Color="Color.Success" OnClick="AddAsync" Icon="@AddButtonIcon" Text="@AddButtonText" />
<TableToolbarButton TItem="TItem" Color="Color.Success" OnClick="AddAsync" Icon="@AddButtonIcon" Text="@AddButtonText" IsDisabled="GetAddButtonStatus()" />
}
@if (!IsExcel && ShowEditButton)
{
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 @@ -725,13 +725,19 @@ public async Task ExpandDetailRow(TItem item)
public string? AlignRightTooltipText { get; set; }

/// <summary>
/// 获得/设置 删除按钮是否禁用回调方法
/// 获得/设置 新建按钮是否禁用回调方法 默认 null 未设置
/// </summary>
[Parameter]
public Func<List<TItem>, bool>? DisableAddButtonCallback { get; set; }

/// <summary>
/// 获得/设置 删除按钮是否禁用回调方法 默认 null 未设置
/// </summary>
[Parameter]
public Func<List<TItem>, bool>? DisableDeleteButtonCallback { get; set; }

/// <summary>
/// 获得/设置 编辑按钮是否禁用回调方法
/// 获得/设置 编辑按钮是否禁用回调方法 默认 null 未设置
/// </summary>
[Parameter]
public Func<List<TItem>, bool>? DisableEditButtonCallback { get; set; }
Expand Down Expand Up @@ -1469,6 +1475,8 @@ public async Task ResetSortAsync()
await QueryData();
}

private bool GetAddButtonStatus() => DisableAddButtonCallback?.Invoke(SelectedRows) ?? false;

/// <summary>
/// 返回 true 时按钮禁用
/// </summary>
Expand Down
39 changes: 39 additions & 0 deletions test/UnitTest/Components/TableTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6344,6 +6344,45 @@ public void DisableEditButtonCallback_Ok()
Assert.True(editButton.Instance.IsDisabled);
}

[Fact]
public void DisableAddButtonCallback_Ok()
{
var localizer = Context.Services.GetRequiredService<IStringLocalizer<Foo>>();
var items = Foo.GenerateFoo(localizer, 2);
var cut = Context.RenderComponent<BootstrapBlazorRoot>(pb =>
{
pb.AddChildContent<Table<Foo>>(pb =>
{
pb.Add(a => a.RenderMode, TableRenderMode.Table);
pb.Add(a => a.Items, items);
pb.Add(a => a.ShowToolbar, true);
pb.Add(a => a.TableColumns, foo => builder =>
{
builder.OpenComponent<TableColumn<Foo, string>>(0);
builder.AddAttribute(1, "Field", "Name");
builder.AddAttribute(2, "FieldExpression", Utility.GenerateValueExpression(foo, "Name", typeof(string)));
builder.CloseComponent();
});
pb.Add(a => a.SelectedRows, [items[0]]);
});
});

var buttons = cut.FindComponents<Button>();
var editButton = buttons.First(i => i.Instance.Text == "新建");
Assert.False(editButton.Instance.IsDisabled);

// 新建按钮被禁用
var table = cut.FindComponent<Table<Foo>>();
table.SetParametersAndRender(pb =>
{
pb.Add(a => a.DisableAddButtonCallback, items =>
{
return true;
});
});
Assert.True(editButton.Instance.IsDisabled);
}

[Fact]
public void ShowDeleteButton_Ok()
{
Expand Down