Use DropDown MultiSelect as FilterTemplate

I'm trying to use <RadzenDataGrid/> with active Multiple=true as <FilterTemplate/> for <RadzenDataGrid/> and it throws error: Unhandled exception rendering component: Object must implement IConvertible.

Any clue?

sample code:

<RadzenDataGrid ... FilterValue="@filterSupplier">
 <RadzenDataGridColumn TItem="MachineTypeModel" Property="Supplier.Name" Title="Supplier" SortOrder="SortOrder.Ascending" FilterValue="@filterSupplier">
                    <FilterTemplate>
                        <RadzenDropDown Data="@colService.Suppliers"
                                        AllowClear=true
                                        Multiple=true
                                        FilterOperator=StringFilterOperator.Contains
                                        AllowFiltering=true
                                        ValueProperty="Name"
                                        FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive"
                                        TextProperty="Name"
                                        @bind-Value=@(filterSupplier) />

                        @*<FilterSupplierTemplate @bind-FilterSupplier=@filterSupplier Multiple=true/>*@
                    </FilterTemplate>
                   </RadzenDataGridColumn>
...
</RadzenDataGrid>

code behind:

@code {
    IEnumerable<string> filterSupplier;
...
}

There are multiple examples showing exactly such functionality and you can compare your implementation with them:

I'm trying, but without success - where am I making a mistake?

Filter component:

@inject ICollectionsService colService;

<RadzenDropDown Data="@colService.Suppliers" //it's a List from DB
                AllowClear=true
                FilterOperator="@FilterOperator"
                Multiple=true
                AllowFiltering=true
                TValue="IEnumerable<string>"
                ValueProperty="Name"
                FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive"
                TextProperty="Name"
                @bind-Value=@(FilteredSuppliers) />

@code {
    private IEnumerable<string>? selectedItems;

    [Parameter]
    public IEnumerable<string>? FilteredSuppliers
    {
        get => selectedItems;
        set
        {
            if (selectedItems == value)
                return;
            selectedItems = value;
            FilteredSuppliersChanged.InvokeAsync(value);
        }
    }

    [Parameter]
    public EventCallback<IEnumerable<string>?> FilteredSuppliersChanged { get; set; }

    [Parameter]
    public StringFilterOperator FilterOperator { get; set; } = StringFilterOperator.Contains;
}

DataGrid:

<RadzenDataGrid @ref=@dg
                        TItem="MachineTypeModel"
                        Data="@colService.MachineTypes"
                        SelectionMode="DataGridSelectionMode.Single"
                        AllowAlternatingRows=true
                        AllowFiltering=true
                        FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive"
                        AllowPaging=true
                        AllowSorting=true
                        ShowMultiColumnSortingIndex=true
                        ShowPagingSummary=true
                        PagerAlwaysVisible=true
                        RowCreate="@OnRowCreatedOrUpdated"
                        RowUpdate="@OnRowCreatedOrUpdated">
            <EmptyTemplate>
                <EmptyGridTemplate/>
             </EmptyTemplate>

            <Columns>
                <RadzenDataGridColumn TItem="MachineTypeModel" Property="Supplier.Name" Title="Supplier" SortOrder="SortOrder.Ascending" FilterValue="@filterSupplier" LogicalFilterOperator="LogicalFilterOperator.Or">
                    <FilterTemplate>
                        <FilterSuppliersTemplate @bind-FilteredSuppliers=@filterSupplier />
                    </FilterTemplate>
                    <EditTemplate Context="item">
                        <EditSupplierTemplate @bind-SelectedSupplierId=item.SupplierId />
                    </EditTemplate>
                </RadzenDataGridColumn>
...

@code {
    IEnumerable<string> filterSupplier;
...
}

it loads correctly, but selecting one of Supplier on FilterDropDown, causing error:

Error: System.InvalidCastException: Object must implement IConvertible.
   at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
   at Radzen.QueryableExtension.ToFilterString[T](IEnumerable`1 columns)
   at Radzen.Blazor.RadzenDataGrid`1.InvokeLoadData(Int32 start, Int32 top)
   at Radzen.Blazor.RadzenDataGrid`1.Reload()
   at Radzen.Blazor.RadzenDataGridColumn`1.SetParametersAsync(ParameterView parameters)

But, when Multiple=false and i change from IEnumerable<string> to string it works fine.

EDIT:
I've added Type="typeof(IEnumerable<string?>)" to this Column and now I don't have an error, but filtering is not working

EDIT 2:
I've managed to get it work. I was missing FilterOperator="FilterOperator.Contains" on Column...
@enchev , maybe after setting Multiple=true should be automatically set also FilterOperator="FilterOperator.Contains" and LogicalFilterOperator="LogicalFilterOperator.Or"? what do You think? Without it, it will not work, right?

1 Like

These are two independents components (DropDown used in FilterTemplate of DataGrid column). We cannot make such dependency.