DxGrid.FilterBy(String, GridFilterRowOperatorType, Object) Method

Filters grid data by the specified value of the data source field.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v21.1.dll

Declaration

public void FilterBy(
    string fieldName,
    GridFilterRowOperatorType operatorType,
    object value
)

Parameters

Name Type Description
fieldName String

Specifies the name of the data source field that supplies data for the filtered column.

operatorType GridFilterRowOperatorType

An enumeration value that specifies the column’s comparison operator.

value Object

Specifies a filter value.

Remarks

The FilterBy method allows you to filter grid data by an individual column’s value. The filter row displays the specified filter value in the corresponding column’s editor. The method call replaces an existing filter value (if any) for the column.

Alternatively, you use the column’s FilterRowValue and FilterRowOperatorType properties instead of the FilterBy method call.

The highlighted code block shows how to add two buttons that filter grid data by the corresponding column’s values.

@using Grid.Northwind
@inject NorthwindContext Northwind

<DxGrid Data="@Data"
        ShowFilterRow="true"
        @ref="MyGrid">
    <Columns>
        <DxGridDataColumn FieldName="OrderId" DisplayFormat="d" />
        <DxGridDataColumn FieldName="OrderDate" DisplayFormat="d" />
        <DxGridDataColumn FieldName="ProductName" />
        <DxGridDataColumn FieldName="UnitPrice" DisplayFormat="c2" />
        <DxGridDataColumn FieldName="Shipped" UnboundType="GridUnboundColumnType.Boolean"
                          UnboundExpression="[ShippedDate] <> Null">
            <CellDisplayTemplate>
                <DxCheckBox CssClass="d-inline-block" Enabled="false" Checked="(bool)context.Value" />
            </CellDisplayTemplate>
        </DxGridDataColumn>
    </Columns>
</DxGrid>

<DxButton Click="@(() => MyGrid.FilterBy("ProductName", GridFilterRowOperatorType.Contains, "Queso"))">Filter By "Product Name"</DxButton>
<DxButton Click="@(() => MyGrid.FilterBy("UnitPrice", GridFilterRowOperatorType.Equal, 12))">Filter By "Unit Price"</DxButton>

@code {
    object Data { get; set; }
    IGrid MyGrid { get; set; }

    protected override void OnInitialized() {
        Data = Northwind.Invoices
            .ToList();
    }
}

Grid - Filter in Code

You can also use the FilterBy method to clear the filter condition in code. To do this, pass null to the method’s value parameter.

<DxButton Click="@(() => MyGrid.FilterBy("ProductName", GridFilterRowOperatorType.Contains, null))">Clear the "Product Name" Filter Condition</DxButton>

To clear all filter conditions in code, call the ClearFilter() method.

See Also