Hi All,
Hopefully someone can point out what I've done wrong.
I have a DataGrid for a print queue. I use simple filters for most columns as this is the user-preferred method. However, print status is a column where users need to filter on multiple values.
I therefore modified the column thus:-
<RadzenDataGridColumn Property="LabelPrintStatusName" Title=@Localiser["status"] Filterable="true" Width="170px" FilterValue="@selectedStatus" FilterOperator="FilterOperator.Contains" LogicalFilterOperator="LogicalFilterOperator.Or">
<FilterTemplate Context="myFilter">
<RadzenDropDown @bind-Value=@selectedStatus class="rz-w-100" Change=@OnSelectedStatusChange Data="@(filterStatus)" AllowClear="true" Multiple="true" />
</FilterTemplate>
</RadzenDataGridColumn>
This uses the two variables
private IEnumerable<string>? selectedStatus = null;
private List<string> filterStatus = [];
And this onchange event handler
private void OnSelectedStatusChange(object value)
{
if (selectedStatus != null && !selectedStatus.Any())
{
selectedStatus = null;
}
}
This works fine. No issues at all.
The problem comes when I've applied a filter and load back the DataGrid settings. I have a LoadDataGridState() function basically straight from the example code and it also works without any issues. Until now.
When I load back the grid settings once I've used my filter Template (above) I get the following error:-
fail: Microsoft.AspNetCore.Components.Server.Circuits.CircuitHost[111]
Unhandled exception in circuit 'P3f5AGiU5cn_dVamak2EY5oHrqJEXSPveUdElYea1XU'.
System.AggregateException: One or more errors occurred. (The requested operation requires an element of type 'String', but the target element has type 'Array'.)
---> System.InvalidOperationException: The requested operation requires an element of type 'String', but the target element has type 'Array'.
at System.Text.Json.ThrowHelper.ThrowJsonElementWrongTypeException(JsonTokenType expectedType, JsonTokenType actualType)
at System.Text.Json.JsonDocument.CheckExpectedType(JsonTokenType expected, JsonTokenType actual)
at System.Text.Json.JsonDocument.GetString(Int32 index, JsonTokenType expectedType)
at System.Text.Json.JsonElement.GetString()
at Radzen.Blazor.RadzenDataGrid`1.GetFilterValue(Object value, Type type)
at Radzen.Blazor.RadzenDataGrid`1.LoadSettingsInternal(DataGridSettings settings, Boolean forceUpdate)
at Radzen.Blazor.RadzenDataGrid`1.OnAfterRenderAsync(Boolean firstRender)
--- End of inner exception stack trace ---
The saved settings for this column being loaded are:-
{
"Columns": [
..
{
"UniqueID": null,
"Property": "LabelPrintStatusName",
"Visible": true,
"Width": "170px",
"OrderIndex": null,
"SortOrder": null,
"SortIndex": null,
"FilterValue": [
"Complete",
"In progress"
],
"FilterOperator": 6,
"SecondFilterValue": null,
"SecondFilterOperator": 0,
"LogicalFilterOperator": 1,
"CustomFilterExpression": null
},
..
],
"Groups": [],
"CurrentPage": 0,
"PageSize": 10
}
If I stop loading back the settings or take off the FilterTemplate from the column, everything works.
What have I done wrong?