CodeBeam.MudBlazor.Extensions icon indicating copy to clipboard operation
CodeBeam.MudBlazor.Extensions copied to clipboard

Is it possible to refresh items if ItemCollection changes dynamically ?

Open diego-cascudo-sop opened this issue 1 year ago • 3 comments
trafficstars

Hello, we are having problems to refresh the popover items, when using ItemCollection and it changes dynamically

selectExtendedRefreshIssue

can you help me to refresh the items ? this is our implementation for the select extended control

<MudSelectExtended T="LeadExplorationFilterValue" @ref="_mudSelectExtended" @bind-SelectedValues="@SelectedValues" ItemCollection="FilterValues" SearchBox="true" SearchBoxClearable="true" SearchBoxAutoFocus="true" OnSearchStringChange="@((search) => GetRefinedFilterValues(search, FilterType))" MultiSelection="true" MultiSelectionTextFunc="@((x) => DisplayText)" Underline="false" Immediate="false" RelativeWidth="false" ToStringFunc="@(x => x?.Text)" Variant="Variant.Text" Margin="Margin.Dense" OpenIcon="@Icons.Material.Filled.ExpandMore" CloseIcon="@Icons.Material.Filled.ExpandLess" AnchorOrigin="Origin.BottomLeft" TransformOrigin="Origin.TopLeft"/>

when searching in the search box we call the GetRefinedFilterValues method, that dispatches the result in our fluxor state

`private void GetRefinedFilterValues(string searchBoxText, LeadExplorationFilterType filterType) { var filter = WellKnownFilterState.Value.Filters.FirstOrDefault(x => x.FilterType == filterType); if (filter == null) return;

    if (filter.FilterType == LeadExplorationFilterType.LegalEntityTypeClass || filter.FilterType == LeadExplorationFilterType.Revenue || filter.FilterType == LeadExplorationFilterType.Size)
        return;

    if (string.IsNullOrEmpty(searchBoxText) || searchBoxText?.Length < 2)
        return;

    Dispatcher.Dispatch(new SearchFilterValuesAction(filterType, searchBoxText));
}`

the filter values are tied directly to the state collection

IList<LeadExplorationFilterValue> FilterValues => WellKnownFilterState.Value?.Filters?.FirstOrDefault(x => x.FilterType == FilterType)?.Values ?? [];

when the refresh event raises we try to refresh the component but that is not working

private async void OnSearchFilterValuesSuccessAction(SearchFilterValuesSuccessAction _) { Console.WriteLine($"Search filter values"); await _mudSelectExtended.ForceRender(true); await _mudSelectExtended.ForceUpdate(); await _mudSelectExtended.ForceRender(true); //RefreshFilter("OnSearchFilterValuesSuccessAction"); }

any help will be welcome !! Thank you !!

diego-cascudo-sop avatar Sep 26 '24 07:09 diego-cascudo-sop

have you tried firing off a "HasStateChanged()"

aarondglover avatar Apr 22 '25 02:04 aarondglover

hey !! hello !! yup we tried, but didn't work not until we changed (in our local devlopment fork) the SelectAllItems to return ItemCollection in teh searchedItems. (MudListExtended.razor.cs)

also added a ForceUpdateValues to execute the StateHasChanged from the component itself public async Task ForceUpdateValues() { Console.WriteLine($"SelectExtended ForceUpdateValues ItemCollection: {JsonSerializer.Serialize(ItemCollection, options)}"); await UpdateValuePropertyAsync(false); await UpdateTextPropertyAsync(false); await BeginValidateAsync();

    StateHasChanged();
}

public void ForceUpdateItemCollection(IList<T?> items) { if (items == null) return;

ItemCollection = items;
_list?.ForceUpdateItemCollection(items);

}

but not sure if that may be a solution. thank you

diego-cascudo-sop avatar Apr 23 '25 10:04 diego-cascudo-sop

It's a hard design pattern issue. If we change ItemCollection to a two way binded property, does it help you? (You can use @bind-ItemCollection:after)

mckaragoz avatar May 01 '25 10:05 mckaragoz