我有一个包含三列的 Radzen DataGrid:名字、姓氏和服务协调员。我希望服务协调员列具有复选框过滤功能。我参考了文档并尝试调整他们的代码来解决这个问题;但是,每当我与表交互时,我都会遇到未处理的异常。
@page "/"
...
@using Radzen;
@using Radzen.Blazor;
<h2>Manage Employee</h2>
<RadzenDataGrid Data="@EmployeeRecords" TItem="ChildRecord"
AllowSorting="true" AllowPaging="true" PageSize="10" AllowFiltering="true" FilterMode="FilterMode.Simple">
<Columns>
<RadzenDataGridColumn TItem="EmployeeRecord" Property="Name.FirstName" Title="First Name" />
<RadzenDataGridColumn TItem="EmployeeRecord" Property="Name.LastName" Title="Last Name" />
<RadzenDataGridColumn TItem="EmployeeRecord" Property="ServiceCoordinator" Title="Customer"
FilterOperator="FilterOperator.Contains" LogicalFilterOperator="LogicalFilterOperator.Or">
<FilterTemplate>
<RadzenDropDown @bind-Value=@selectedServiceCoordinators Style="width:100%;"
Change=@OnSelectedServiceCoordinatorsChange Data="@(serviceCoordinators)" AllowClear="true" Multiple="true" />
</FilterTemplate>
</RadzenDataGridColumn>
</Columns>
</RadzenDataGrid>
@code {
List<string> selectedServiceCoordinators;
List<string> serviceCoordinators = new List<string>();
EmployeeRecord employeeRecord = new EmployeeRecord();
List<EmployeeRecord> EmployeeRecords = new List<EmployeeRecord>();
protected override async Task OnInitializedAsync() {
GetEmployeeRecords();
UpdateServiceCoordinators();
}
private void GetEmployeeRecords() {
EmployeeRecords = EmployeeRecordService.EmployeeRecords();
}
private void UpdateServiceCoordinators() {
foreach (EmployeeRecord c in EmployeeRecords) {
serviceCoordinators.Add(c.ServiceCoordinator);
}
}
void OnSelectedServiceCoordinatorsChange(object value) {
if (selectedServiceCoordinators != null && !selectedServiceCoordinators.Any()) {
selectedServiceCoordinators = null;
}
}
}
我相信
selectedServiceCoordinator
没有正确更新,但我不确定是否要纠正这个错误,因为我依赖于 Radzen 的内部实现。