Blazor Grid Filtering

    The Blazor IgbGrid component provides three different filtering types - Quick filtering, Excel Style Filtering and Advanced Filtering which enable you to display only the records that meet specified criteria. The IgbGrid component in Blazor provides filtering capabilities and extensive filtering API through the data container to which the IgbGrid is bound.

    Blazor Grid Filtering Example

    The sample below demonstrates IgbGrid's Excel Style Filtering user experience.

    Setup

    In order to specify if filtering is enabled and which filtering mode should be used, the IgbGrid exposes the following properties - AllowFiltering, AllowAdvancedFiltering, FilterMode and Filterable.

    Property AllowFiltering enables you to specify the following options:

    • false - the filtering for the corresponding grid will be disabled. This is the default value.
    • true - the filtering for the corresponding grid will be enabled.

    Property AllowAdvancedFiltering enables you to specify the following options:

    • false - the advanced filtering for the corresponding grid will be disabled. This is the default value.
    • true - the advanced filtering for the corresponding grid will be enabled.

    Property FilterMode enables you to specify the following options:

    • QuickFilter - a simplistic filtering UI. This is the default value.
    • ExcelStyleFilter - an Excel-like filtering UI.

    Property Filterable enables you to specify the following options:

    • true - the filtering for the corresponding column will be enabled. This is the default value.
    • false - the filtering for the corresponding column will be disabled.
    <IgbGrid Data=data AutoGenerate=false AllowFiltering=true>
        <IgbColumn Field="ProductName" DataType="GridColumnDataType.String"></IgbColumn>
        <IgbColumn Field="Price" DataType="GridColumnDataType.Number" Filterable=false></IgbColumn>
    </IgbGrid>
    

    To enable the Advanced filtering however, you need to set the AllowAdvancedFiltering input property to true.

    <IgbGrid Data=data AutoGenerate=true AllowAdvancedFiltering=true />
    

    [!Note] You can enable both the QuickFilter or ExcelStyleFilter and the advanced filtering user interfaces in the IgbGrid. Both filtering user interfaces will work independently of one another. The final filtered result in the IgbGrid is the intersection between the results of the two filters.

    Interaction

    In order to open the filter row for a particular column, the 'Filter' chip below its header should be clicked. To add conditions you should choose filter operand using the dropdown on the left of the input and enter value. For number and date columns 'Equals' is selected by default, for string - 'Contains' and for boolean - 'All'. Pressing 'Enter' confirms the condition and you are now able to add another one. There is a dropdown, between 'condition' chips, which determines the logical operator between them, 'AND' is selected by default. To remove a condition you can click the 'X' button of the chip, and to edit it you should select the chip and the input will be populated with the chip's data. While filter row is opened you can click on any filterable column's header in order to select it and to be able to add filter conditions for it.

    While some filtering conditions have been applied to a column, and the filter row is closed, you can either remove the conditions by clicking the chip's close button, or you can open the filter row by selecting any of the chips. When there is not enough space to show all the conditions, a filter icon is shown with a badge that indicates how many more conditions there are. It can also be clicked in order to open the filter row.

    Usage

    There's a default filtering strategy provided out of the box, as well as all the standard filtering conditions, which the developer can replace with their own implementation. In addition, we've provided a way to easily plug in your own custom filtering conditions. The IgbGrid currently provides not only a simplistic filtering UI, but also more complex filtering options. Depending on the set DataType of the column, the correct set of filtering operations is loaded inside the filter UI dropdown. Additionally, you can set the IgnoreCase and the initial Condition properties.

    The filtering feature is enabled for the IgbGrid component by setting the AllowFiltering input to true. The default FilterMode is QuickFilter and it cannot be changed run time. To disable this feature for a certain column – set the Filterable input to false.

    <IgbGrid Data=data AutoGenerate=false AllowFiltering=true>
        <IgbColumn Field="ProductName" DataType="GridColumnDataType.String"></IgbColumn>
        <IgbColumn Field="Price" DataType="GridColumnDataType.Number" Filterable=false></IgbColumn>
    </IgbGrid>
    

    [!Note] If values of type string are used by a column of data type date, the IgbGrid won't parse them to date objects and using filtering conditions won't be possible. If you want to use string objects, additional logic should be implemented on the application level, in order to parse the values to date objects.

    You can filter any column or a combination of columns through the IgbGrid API. The IgbGrid exposes several methods for this task - Filter, FilterGlobal and ClearFilter.

    • Filter - filter a single column or a combination of columns.

    There are five filtering operand classes exposed:

    • IgbFilteringOperand: this is a base filtering operand, which can be inherited when defining custom filtering conditions.
    • BooleanFilteringOperand defines all default filtering conditions for boolean type.
    • NumberFilteringOperand defines all default filtering conditions for numeric type.
    • StringFilteringOperand defines all default filtering conditions for string type.
    • DateFilteringOperand defines all default filtering conditions for date type.

    The only required parameters are the column field key and the filtering term. Both the condition and the case sensitivity will be inferred from the column properties if not provided. In the case of multiple filtering, the method accepts an array of filtering expressions.

    [!Note] The filtering operation DOES NOT change the underlying data source of the IgbGrid.

    • FilterGlobal - clears all existing filters and applies the new filtering condition to all Grid's columns.
    • ClearFilter - removes any applied filtering from the target column. If called with no arguments it will clear the filtering of all columns.

    Initial filtered state

    To set the initial filtering state of the IgbGrid, set the IgbGrid FilteringExpressionsTree property to an array of FilteringExpressionsTree for each column to be filtered.

    Filtering logic

    The FilteringLogic property of the IgbGrid controls how filtering multiple columns will resolve in the IgbGrid. You can change it at any time through the IgbGrid API, or through the IgbGrid input property.

    The default value of AND returns only the rows that match all the currently applied filtering expressions. Following the example above, a row will be returned when both the 'ProductName' cell value contains 'myproduct' and the 'Price' cell value is greater than 55.

    When set to OR, a row will be returned when either the 'ProductName' cell value contains 'myproduct' or the 'Price' cell value is greater than 55.

    Custom Filtering Operands

    You can customize the filtering menu by adding, removing or modifying the filtering operands. By default, the filtering menu contains certain operands based on the column’s data type (BooleanFilteringOperand, DateFilteringOperand, NumberFilteringOperand and StringFilteringOperand). You can extend these classes or their base class IgbFilteringOperand to change the filtering menu items’ behavior.

    In the sample below, inspect the “Product Name” and “Discontinued” columns filters menus. For the “Discontinued” column filter, we have limited the number of operands to All, True and False. For the “Product Name” column filter – we have modified the Contains and Does Not Contain operands logic to perform case sensitive search and added also Empty and Not Empty operands.

    To do that, extend the StringFilteringOperand and BooleanFilteringOperand, modify the operations and their logic, and set the column filters input to the new operands.

    Known Limitations

    [!Note] Some browsers such as Firefox fail to parse regional specific decimal separators by considering them grouping separators, thus resulting in them being invalid. When inputting such values for a numeric column filter value, only the valid part of the number will be applied to the filtering expression. For further information, refer to the Firefox issue.

    API References

    Additional Resources

    Our community is active and always welcoming to new ideas.