Skip to content

Commit

Permalink
feat(MultiFilter): keep selected item when AlwaysTriggerGetItems is t…
Browse files Browse the repository at this point in the history
…rue (#3800)

* fix: 修复逻辑判断错误

* feat: 增加保持选项功能

* chore: bump version 8.7.1-beta08

* test: 更新单元测试
  • Loading branch information
ArgoZhang authored Jul 6, 2024
1 parent 4affe60 commit bb50e0b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
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>8.7.1-beta07</Version>
<Version>8.7.1-beta08</Version>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">
Expand Down
19 changes: 17 additions & 2 deletions src/BootstrapBlazor/Components/Filters/MultiFilter.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,30 @@ public override FilterKeyValueAction GetFilterConditions()
}

/// <summary>
/// Javascript 回调方法
/// JavaScript 回调方法
/// </summary>
/// <returns></returns>
[JSInvokable]
public async Task TriggerGetItemsCallback()
{
if (OnGetItemsAsync != null)
{
_source = await OnGetItemsAsync();
var items = await OnGetItemsAsync();
if (_source != null)
{
var selectedItems = _source.Where(i => i.Active).ToList();
if (selectedItems.Count > 0)
{
foreach (var item in items)
{
if (selectedItems.Find(i => item.Value == i.Value) != null)
{
item.Active = true;
}
}
}
}
_source = items;
StateHasChanged();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function init(id, options) {
const popoverEl = filterEl.querySelector('i[data-bs-toggle="bb.dropdown"]');
if (popoverEl) {
EventHandler.on(popoverEl, 'show.bs.popover', () => {
if (alwaysTrigger === true) {
if (alwaysTrigger === false) {
EventHandler.off(popoverEl, 'show.bs.popover');
}
invoker.invokeMethodAsync(callback);
Expand Down
5 changes: 5 additions & 0 deletions test/UnitTest/Components/TableFilterTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ public async Task MultiFilter_Ok()
});
cut.Contains("loading-template-test");
await cut.InvokeAsync(() => filter.Instance.TriggerGetItemsCallback());

// 选中数据
var checkItems = cut.FindComponents<Checkbox<bool>>();
await cut.InvokeAsync(() => checkItems[1].Instance.SetValue(true));
await cut.InvokeAsync(() => filter.Instance.TriggerGetItemsCallback());
}

[Fact]
Expand Down

0 comments on commit bb50e0b

Please sign in to comment.