CheckBoxList FilterMode default value

How do you set a default value if using CheckBoxList filter?

Specifically, I have an Active column and I want to default the filter to only show Active = True

                <RadzenDataGridColumn TItem="RadzenBlazorServerApp.Models.sql_database.Load" Property="Active" Title="Active" FilterValue="true">
                </RadzenDataGridColumn>

When I add in FilterValue="true" which I was hoping would work, I get an error:

CheckBoxList filter require enumerable of values for FilterValue instead single value. For example in this demo:

protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        await base.OnAfterRenderAsync(firstRender);

        if(firstRender)
        {
            var column = grid.ColumnsCollection.Where(c => c.Property == "ProductDiscontinued").FirstOrDefault();

            if(column != null)
            {
                column.SetFilterValue(new bool?[]{ true });
                await grid.Reload();
            }
        }
    }

thank you. while I try that, i have another filter I'd like to set

<RadzenDataGridColumn TItem="RadzenBlazorServerApp.Models.sql_database.Load" Property="SystemLoadStatus.Abbreviation" Title="Status">
</RadzenDataGridColumn>

there are 5 possible statuses, I want to default the filter to select 4 of the 5.

I can't get the first filter of the bool property working.

I believe I have it set up like the demo. see code below.

On Debug it is finding the column and he executes the line to set the filter, but I get this error:

    protected override async Task OnInitializedAsync()
    {
        var pleaseSelect = "Bulk Operation";
        bulkOperations.Add(pleaseSelect);
        bulkOperations.Add("Delete Empty Selected Loads");
        selectedBulkOperation = pleaseSelect;
        blobBaseURL = Configuration.GetSection("Azure")["BlobBaseURL"] + "files/";
    }

    [Parameter]
    public int LoadId { get; set; }
    protected override async Task OnParametersSetAsync()
    {
        await GetLoads();
        if (LoadId != 0)
            loads = loads.Where(x => x.Id == LoadId);
        loads = loads.AsQueryable();
    }

    protected IEnumerable<RadzenBlazorServerApp.Models.sql_database.Load> loads;
    private async Task GetLoads()
    {
        loads = await sql_databaseService.GetLoads(new Query
        {
            Filter = $@"i => i.TenantId==" + Security.Tenant.Id + $@" &&
                    (i.AltLoadNameNum.Contains(@0) ||
                    i.AltLoadNameNumTempForDropDownOnly.Contains(@0) ||
                    i.AvcNameNum.Contains(@0) ||
                    i.SalesRepUserId.Contains(@0) ||
                    i.OriginCity.Contains(@0) ||
                    i.OriginStateProv.Contains(@0) ||
                    i.DestinationCity.Contains(@0) ||
                    i.DestinationStateProv.Contains(@0) ||
                    i.Vehicles.Any(v => v.ReferenceNumber.Contains(@0)) ||
                    i.Vehicles.Any(v => v.ExternalInvoiceNumber.Contains(@0)) ||
                    i.Vehicles.Any(v => v.VIN.Contains(@0)) ||
                    i.ManifestOverride.Contains(@0))",
            FilterParameters = [search],
            Expand = "AspNetTenant,SystemLoadStatus,Truck,Driver,Carrier,AspNetUser,Vehicles"
        });
    }

    protected RadzenDataGrid<RadzenBlazorServerApp.Models.sql_database.Load> grid0;
    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        await base.OnAfterRenderAsync(firstRender);

        if (firstRender)
        {
            var column = grid0.ColumnsCollection.Where(c => c.Property == "Active").FirstOrDefault();

            if (column != null)
            {
                column.SetFilterValue(new bool?[] { true });
                await grid0.Reload();
            }
        }
    }

<RadzenDataGridColumn TItem="RadzenBlazorServerApp.Models.sql_database.Load" Property="Active" Title="Active">
</RadzenDataGridColumn>

public partial class Load
{
    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public int Id { get; set; }

    [Required]
    public int TenantId { get; set; }

    public AspNetTenant AspNetTenant { get; set; }

    [Required]
    public int TenantLoadId { get; set; }

    public bool Active { get; set; }

...

Make sure your property is nullable bool, if not you should use:

column.SetFilterValue(new bool[] { true });
1 Like

thank you very much.

I was able to apply the same principle and get the other column filtered as well.

    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        if (firstRender)
        {
            var column = grid0.ColumnsCollection.Where(c => c.Property == "Active").FirstOrDefault();

            if (column != null)
            {
                column.SetFilterValue(new bool[] { true });
            }
            var statusColumn = grid0.ColumnsCollection.Where(c => c.Property == "SystemLoadStatus.Abbreviation").FirstOrDefault();

            if (statusColumn != null)
            {
                statusColumn.SetFilterValue(new string[] { "DLV", "DSP", "PCK", "RLS" });
            }
            await grid0.Reload();
        }
    }