CodeBeam.MudBlazor.Extensions
CodeBeam.MudBlazor.Extensions copied to clipboard
Is it possible to refresh items if ItemCollection changes dynamically ?
Hello, we are having problems to refresh the popover items, when using ItemCollection and it changes dynamically
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 !!
have you tried firing off a "HasStateChanged()"
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
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)