How can I choose options for column filters of DataGrid

I want to remove the "Is null", "Is not null", "Is empty", and "Is not empty" options from the available column filter options. How can I do this?

image

Hi @CO26,

Check the Blazor DataGrid Filter API demo. You need to create a custom column which overrides the GetFilterOperators method:

MyCustomDataGridColumn.razor

@typeparam TItem
@inherits RadzenDataGridColumn<TItem>

@code {
    public override IEnumerable<FilterOperator> GetFilterOperators()
    {
        var operators = base.GetFilterOperators();

        if (FilterPropertyType == typeof(DateTime?))
        {
            operators = operators.Where(o => o != FilterOperator.IsNull && o != FilterOperator.IsNotNull);
        }

        return operators;
    }

    public override bool ShowTimeForDateTimeFilter()
    {
        return false;
    }
}
<RadzenDataGrid ...>
  <Columns>
      <MyCustomDataGridColumn TItem="Employee" Property="BirthDate" Title="Birth Date" FormatString="{0:d}" />
      <RadzenDataGridColumn TItem="Employee" Property="Country" Title="Country" />
      <RadzenDataGridColumn TItem="Employee" Property="Notes" Title="Notes" />
  </Columns>
</RadzenDataGrid>
1 Like

Hey, does this actually work though?

Because in the demo example you linked the RadzenDataGrid component has FilterMode="FilterMode.Simple" set, so there is no way to tell.

On the same demo page, when I'll change filter mode to SimpleWithMenu or Advanced and re-run the code, the column "Birth date" (which I'm assuming is of type DateTime?) still contains IsNull and IsNotNull filter operators...

Should work fine with the latest release.

It seems to work now, thanks!