Hi,
I want to automatically show the FilterBar (AllowFiltering binding) if a filter is persisted (EnablePersistence=true).
I set the value of the binding to true if the grid has persisted a filter but the FilterBar is enabled if I leave and reenter the component.
Which events I have to use to rerender the grid that it shows the FilterBar?
Greetings!
Thats the grid: (removed the colums for space)
<SfGrid @ref="@gridParameter" TValue="LoHiParameter" Height="100%" ShowColumnMenu="true" @bind-AllowFiltering="@ParameterComponentParameterAdaptor.ShowFiltering" @bind-AllowGrouping="@ParameterComponentParameterAdaptor.ShowGrouping" AllowPaging="true" AllowSorting="true" AllowReordering="true" AllowResizing="true" RowHeight="38" AllowSelection="true" ID="parameterGridParameterComponent" EnablePersistence="true">
<SfDataManager AdaptorInstance="@typeof(ParameterComponentParameterAdaptor)" Adaptor="Adaptors.CustomAdaptor">
<GridEvents TValue="LoHiParameter" RowSelected="@RowSelected" DataBound="@DataBoundHandler" OnActionComplete="@ActionComplete"/>
</SfDataManager>
<GridEditSettings AllowEditing="true" Mode="@Syncfusion.Blazor.Grids.EditMode.Normal" />
<GridFilterSettings Mode="FilterBarMode.Immediate" ImmediateModeDelay="200" Type="Syncfusion.Blazor.Grids.FilterType.FilterBar" />
<GridPageSettings PageSizes="@DefaultPageSizes" PageSize="20" />
<SfToolbar>
<ToolbarItems>
<ToolbarItem Align="ItemAlign.Center">
<Template>
@{
var filtered = gridParameter?.FilterSettings?.Columns;
if (filtered != null && filtered.Any())
{
<a style="margin-top: 12px; color: #ff2d37; font-size:smaller;">Filter active!</a>
}
}
</Template>
</ToolbarItem>
<ToolbarItem Text="Filtering" Type="ItemType.Input" Align="ItemAlign.Right">
<Template>
<SfCheckBox @bind-Checked="@ParameterComponentParameterAdaptor.ShowFiltering" Label="Filter" LabelPosition="LabelPosition.Before" />
</Template>
</ToolbarItem>
<ToolbarItem Text="Grouping" Type="ItemType.Input" Align="ItemAlign.Right">
<Template>
<SfCheckBox @bind-Checked="@ParameterComponentParameterAdaptor.ShowGrouping" Label="Group" LabelPosition="LabelPosition.Before" />
</Template>
</ToolbarItem>
</ToolbarItems>
</SfToolbar>
</SfGrid>
method to enable filter bar
public async void AutoEnableFilterFeature<T>(SfGrid<T> grid, CustomAdaptor<T> adaptor)
where T : ILoHi
{
if (grid != null)
{
var filtered = grid.FilterSettings?.Columns;
if (filtered != null && filtered.Any())
adaptor.ShowFiltering = true;
}
}
This method should enable the filter bar. Where should this method be called? Tested in many events: OnParameterSet, DataBound, ... The best result is that the checkbox in the ToolBar is checked but the FilterBar is not visible; its just visible if the component (or control) is rerendered again (ex: leave and reenter page
|
<SfGrid TValue="Order" @ref="UsersGrid" ... AllowFiltering="@ShowFilter" ... EnablePersistence="true">
<GridEvents TValue="Order" OnActionComplete="ActionComplete"></GridEvents>
...
</SfGrid>
[Inject]
public AppStateService AppStateService { get; set; }
public bool ShowFilter { get; set; } = false;
...
public async void ActionComplete(ActionEventArgs<Order> args)
{
//This event will be triggered for every Data operations
//store the persist data
AppStateService.TimeGridPersistData = await this.UsersGrid.GetPersistData();
}
protected override void OnInitialized()
{
//based on the persist data enable the AllowFiltering dynamically based on whether filtersettings is persisted
if(AppStateService.TimeGridPersistData != null){
dynamic PersistProp = JsonSerializer.Deserialize<Dictionary<string, object>>(AppStateService.TimeGridPersistData.ToString());
dynamic _statek = JsonSerializer.Deserialize<GridFilterSettings>(PersistProp["filterSettings"].ToString());
if (_statek.Columns != null) //based on the filter columns enable ShowFilter
{
ShowFilter = true;
}
}
...
}
|
I dont understand your proposal!
I dont have problems to get or set the value for "ShowFilter" binding! This is working fine!
The problem is that when the component is rendered and the control is shown, the ShowFilter property has the value 'true' but the FilterBar isnt visible...
maybe I found the reason why its not working...
It seems that on the first render the controller cannot filter the data if a filter is persisted?
I got an exception when I call the PerformFiltering method in the controller:
internal IQueryable<T> Filter<T>(IQueryable<T> loHis) {
if (dataManagerRequest != null && dataManagerRequest.Where != null && dataManagerRequest.Where.Any()) {
loHis = DataOperations.PerformFiltering(loHis, dataManagerRequest.Where, dataManagerRequest.Where[0].Condition);
}
return loHis;
}
If I set EnablePersistence=false then the issue is not occuring and filtering is working fine!
|
<div>@isFilterEnabled</div>
<SfButton OnClick="OnClick">Enable Filter</SfButton>
public bool isFilterEnabled{ get; set; }
public void OnClick()
{
isFilterEnabled = UsersGrid.AllowFiltering;
}
|
Thx for the update! I guess I understand now what you mean!
But there is still a problem:
On my project your proposal is not working after restarting the project! The reason is I cannot read the PersistedData of the grid in the OnInitzilized method because the grid object is null at this point!
I guess I got it:
I am using the OnAfterRenderAsync method to read and set the persisted data!
Thx for your help!
PS: Is there an equivalent to TreeGrid?