After adding a LoadData method on the CheckBoxFilter demo, filtering on the Product Name column fails.
With the code below, filter on the Product Name column, it errors on query.Where(args.Filter)
Blazor DataGrid Component - Excel like filtering | Free UI Components by Radzen
@using RadzenBlazorDemos.Data
@using RadzenBlazorDemos.Models.Northwind
@using Microsoft.EntityFrameworkCore
@using System.Text.Json
@using System.Linq.Dynamic.Core;
@using System.Text.Json.Serialization
@inherits DbContextPage
<style>
.rz-grid-table {
width: unset;
}
</style>
<RadzenDataGrid @ref="grid" AllowFiltering="true" AllowColumnResize="true"
FilterMode="FilterMode.CheckBoxList" PageSize="5" AllowPaging="true" AllowSorting="true" Data="@orders"
AllowColumnPicking="true"
LoadData="GridLoadData"
>
<Columns>
<RadzenDataGridColumn Property="OrderID" Title="Order ID" />
<RadzenDataGridColumn @ref=ProductNameColumn Property="@nameof(Order.OrderDetails)" FilterProperty="Product.ProductName" Title="Product Name"
Type="typeof(IEnumerable<OrderDetail>)" Sortable="false" FilterOperator="FilterOperator.In">
<Template>
@(string.Join(", ", context.OrderDetails.Select(od => od.Product.ProductName)))
</Template>
</RadzenDataGridColumn>
<RadzenDataGridColumn Property="Customer.CompanyName" Title="Customer" AllowCheckBoxListVirtualization="false" />
<RadzenDataGridColumn Property="ProductDiscontinued" Title="Discontinued" FormatString="{0}" FormatProvider="@myBooleanProvider" />
<RadzenDataGridColumn Property="Employee.LastName" Title="Employee">
<Template Context="order">
<RadzenImage Path="@order.Employee?.Photo" Style="width: 32px; height: 32px;" class="rz-border-radius-4 rz-me-2" AlternateText="@(order.Employee?.FirstName + " " + order.Employee?.LastName)" />
@order.Employee?.FirstName @order.Employee?.LastName
</Template>
</RadzenDataGridColumn>
<RadzenDataGridColumn Property="@nameof(Order.OrderDate)" Title="Order Date" FormatString="{0:d}" />
<RadzenDataGridColumn Property="@nameof(Order.RequiredDate)" Title="Required Date" FormatString="{0:d}" />
<RadzenDataGridColumn Property="@nameof(Order.ShippedDate)" Title="Shipped Date" FormatString="{0:d}" />
<RadzenDataGridColumn Property="@nameof(Order.ShipName)" Title="Ship Name" />
<RadzenDataGridColumn Property="@nameof(Order.ShipCountry)" Title="Ship Country" />
</Columns>
</RadzenDataGrid>
@code {
IEnumerable<Order> allOrders;
List<Order> orders;
RadzenDataGrid<Order> grid;
MyBooleanProvider myBooleanProvider = new MyBooleanProvider();
RadzenDataGridColumn<Order> ProductNameColumn { get; set; }
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
allOrders = orders = await Task.FromResult(dbContext.Orders.Include("OrderDetails.Product").Include("Customer").Include("Employee").ToList().Select(o =>
{
o.ProductDiscontinued = o.OrderDetails.FirstOrDefault()?.Product?.Discontinued;
return o;
}).ToList());
}
public class MyBooleanProvider : IFormatProvider, ICustomFormatter
{
public string Format(string format, object arg, IFormatProvider formatProvider)
{
return object.Equals(arg, true) ? "Yes" : object.Equals(arg, false) ? "No" : "No value";
}
public object GetFormat(Type formatType)
{
if (formatType == typeof(ICustomFormatter))
{
return this;
}
return null;
}
}
private void GridLoadData(LoadDataArgs args)
{
var options = new JsonSerializerOptions() { WriteIndented = true };
options.Converters.Add(new JsonStringEnumConverter() );
Console.WriteLine(JsonSerializer.Serialize(args,options));
var query = allOrders.ToList().AsQueryable();
if (!String.IsNullOrEmpty(args.Filter))
{
query = query.Where(args.Filter);
}
if (!String.IsNullOrEmpty(args.OrderBy))
{
query = query.OrderBy(args.OrderBy);
}
if (grid.AllowPaging && args.Skip.HasValue && args.Top.HasValue)
query = query.Skip(args.Skip.Value).Take(args.Top.Value);
orders.Clear();
orders.AddRange(query.ToList());
}
}