Skip to content

Commit

Permalink
other filtering demos improved to respect auto-filter setting in temp…
Browse files Browse the repository at this point in the history
…late filters
  • Loading branch information
enchev committed Aug 1, 2023
1 parent d7c2fb8 commit 8db9fc3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
16 changes: 14 additions & 2 deletions RadzenBlazorDemos/Pages/DataFilterLoadData.razor
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
<RadzenStack Orientation="Orientation.Horizontal" Gap="0.5rem" AlignItems="AlignItems.Center" Class="rz-p-4 rz-border-radius-1" Style="border: var(--rz-grid-cell-border);">
<RadzenCheckBox @bind-Value="@auto" Name="auto" />
<RadzenLabel Text="Auto filter" Component="auto" Class="rz-me-6" />
<RadzenButton Text="Apply Filter" Click="@(args => dataFilter.Filter())" Disabled="@auto" Size="ButtonSize.Small" />
<RadzenButton Text="Apply Filter" Click="@ApplyFilter" Disabled="@auto" Size="ButtonSize.Small" />
</RadzenStack>

<RadzenDataFilter @ref="dataFilter" Auto=auto Data="@orders" TItem="Order" ViewChanged=@(view => ordersGrid.Reload())>
<Properties>
<RadzenDataFilterProperty TItem="Order" Property="OrderID" Title="Order ID" />
<RadzenDataFilterProperty TItem="Order" Property="Employee.LastName" Title="Employee Last Name" />
<MyCustomEnumerableDataFilterProperty TItem="Order" Property="Employee.Title" Title="Employee Title" FilterValue="@selectedTitles"
<MyCustomEnumerableDataFilterProperty TItem="Order" Property="Employee.Title" Title="Employee Title" FilterValue="@finalSelectedTitles"
Type="typeof(IEnumerable<string>)" FilterOperator="FilterOperator.Contains">
<FilterTemplate>
<RadzenDropDown @bind-Value=@selectedTitles Style="width:100%;"
Expand Down Expand Up @@ -69,6 +69,7 @@

List<string> titles = new List<string> { "Sales Representative", "Vice President, Sales", "Sales Manager", "Inside Sales Coordinator" };
IEnumerable<string> selectedTitles;
IEnumerable<string> finalSelectedTitles;

async Task OnSelectedTitlesChange(object value)
{
Expand All @@ -77,9 +78,20 @@
selectedTitles = null;
}

if (auto)
{
finalSelectedTitles = selectedTitles;
}

await ordersGrid.FirstPage();
}

async Task ApplyFilter()
{
finalSelectedTitles = selectedTitles;
await dataFilter.Filter();
}

protected override async Task OnAfterRenderAsync(bool firstRender)
{
await base.OnAfterRenderAsync(firstRender);
Expand Down
16 changes: 14 additions & 2 deletions RadzenBlazorDemos/Pages/DataFilterOData.razor
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
<RadzenStack Orientation="Orientation.Horizontal" Gap="0.5rem" AlignItems="AlignItems.Center" Class="rz-p-4 rz-border-radius-1" Style="border: var(--rz-grid-cell-border);">
<RadzenCheckBox @bind-Value="@auto" Name="auto" />
<RadzenLabel Text="Auto filter" Component="auto" Class="rz-me-6" />
<RadzenButton Text="Apply Filter" Click="@(args => dataFilter.Filter())" Disabled="@auto" Size="ButtonSize.Small" />
<RadzenButton Text="Apply Filter" Click="@ApplyFilter" Disabled="@auto" Size="ButtonSize.Small" />
</RadzenStack>

<RadzenDataFilter @ref="dataFilter" Auto=auto Data="@orders" TItem="Order" ViewChanged=@(view => ordersGrid.Reload())>
<Properties>
<RadzenDataFilterProperty TItem="Order" Property="OrderID" Title="Order ID" />
<RadzenDataFilterProperty TItem="Order" Property="Employee.LastName" Title="Employee Last Name" />
<MyCustomEnumerableDataFilterProperty TItem="Order" Property="Employee.Title" Title="Employee Title" FilterValue="@selectedTitles"
<MyCustomEnumerableDataFilterProperty TItem="Order" Property="Employee.Title" Title="Employee Title" FilterValue="@finalSelectedTitles"
Type="typeof(IEnumerable<string>)" FilterOperator="FilterOperator.Contains">
<FilterTemplate>
<RadzenDropDown @bind-Value=@selectedTitles Style="width:100%;"
Expand Down Expand Up @@ -68,6 +68,7 @@

List<string> titles = new List<string> { "Sales Representative", "Vice President, Sales", "Sales Manager", "Inside Sales Coordinator" };
IEnumerable<string> selectedTitles;
IEnumerable<string> finalSelectedTitles;

async Task OnSelectedTitlesChange(object value)
{
Expand All @@ -76,9 +77,20 @@
selectedTitles = null;
}

if (auto)
{
finalSelectedTitles = selectedTitles;
}

await ordersGrid.FirstPage();
}

async Task ApplyFilter()
{
finalSelectedTitles = selectedTitles;
await dataFilter.Filter();
}

protected override async Task OnAfterRenderAsync(bool firstRender)
{
await base.OnAfterRenderAsync(firstRender);
Expand Down

0 comments on commit 8db9fc3

Please sign in to comment.