Hi there!
I like new checkbox filter, but i dunno how to use it for collection properties...
I've got column with task performers (sometimes more than one for each task), and i use template to show them as one string:
<RadzenDataGridColumn TItem="Task" Property="Performers" Title="Task performers" Width="auto"
FilterProperty="Performers">
<Template Context="data">
<RadzenLabel Text="@(string.Join(", ", data.Performers.Select(p => p.Employee?.DisplayString)))" ></RadzenLabel>
</Template>
</RadzenDataGridColumn>
But I have no idea how to set my property collection data to checkbox filter. FilterProperty="Performesr.Employee.DisplayString" aslo not work.
Is there any way to do it with default markup? Or only way is to use custom filter template?
Thanks in advance!
enchev
July 29, 2024, 5:40am
2
Not supported out-of-the-box, only with custom template.
Sad, but ok, thanks anyway!
enchev
July 29, 2024, 12:02pm
4
There are plenty of examples in our demos on how to create custom FilterTemplate with CheckBoxList:
1 Like
enchev
July 29, 2024, 1:08pm
5
Here is something that will work out-of-the-box in our next update before the end of the week:
@using RadzenBlazorDemos.Data
@using RadzenBlazorDemos.Models.Northwind
@using Microsoft.EntityFrameworkCore
@inherits DbContextPage
<RadzenDataGrid @ref=grid AllowPaging="true" AllowSorting="true" AllowFiltering="true" Data="@orders" FilterMode="FilterMode.CheckBoxList">
<Columns>
<RadzenDataGridColumn Property="Customer.CompanyName" Title="Company Name" />
<RadzenDataGridColumn Property="OrderDetails" FilterProperty="Product.ProductName" Title="Product Name" Type="typeof(IEnumerable<OrderDetail>)" Sortable="false">
<Template>
@(string.Join(',', context.OrderDetails.Select(od => od.Product.ProductName)))
</Template>
</RadzenDataGridColumn>
</Columns>
</RadzenDataGrid>
@code {
RadzenDataGrid<Order> grid;
IQueryable<Order> orders;
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
orders = dbContext.Orders.Include("OrderDetails.Product").Include("Customer").ToList().AsQueryable();
}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
var column = grid.ColumnsCollection.Where(c => c.Property == "OrderDetails").FirstOrDefault();
if (column != null)
{
column.SetFilterValue(new string[] { "Tofu" });
column.SetFilterOperator(FilterOperator.In);
await grid.Reload();
}
}
await base.OnAfterRenderAsync(firstRender);
}
}
1 Like