React Grid Filtering

    The Ignite UI for React Filtering in React Grid is a feature that allows for selectively displaying or hiding data based on specific criteria or conditions. There is a bound data container through which the IgrGrid Component provides rich filtering API and all the filtering capabilities. The available filtering types here are three:

    React Grid Filtering Example

    The sample below demonstrates IgrGrid's Quick Filter user experience.

    Setup

    In order to specify if filtering is enabled and which filtering mode should be used, the IgrGrid 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.
    <IgrGrid data={this.nwindData} autoGenerate="false" ref={this.gridRef} allowFiltering="true">
        <IgrColumn field="ProductName" dataType="String"></IgrColumn>
        <IgrColumn field="UnitPrice" data-type="Number" filterable="false"></IgrColumn>
    </IgrGrid>
    

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

    <IgrGrid data={nwindData} autoGenerate="false" ref={gridRef} allowAdvancedFiltering="true">
    </IgrGrid>
    

    [!Note] You can enable both the QuickFilter or ExcelStyleFilter and the advanced filtering user interfaces in the IgrGrid. Both filtering user interfaces will work independently of one another. The final filtered result in the IgrGrid 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 IgrGrid 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 IgrGrid 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.

    <IgrGrid autoGenerate="false" allowFiltering="true">
        <IgrColumn field="ProductName" dataType="String"></IgrColumn>
        <IgrColumn field="Price" dataType="Number"></IgrColumn>
        <IgrColumn field="Discontinued" dataType="Boolean" filterable="false"></IgrColumn>
    </IgrGrid>
    

    [!Note] If values of type string are used by a column of data type date, the IgrGrid 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.

    Filtering logic

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

    import { FilteringLogic } from "igniteui-react-grids";
    
    <IgrGrid filteringLogic={FilteringLogic.Or}></IgrGrid>
    

    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.

    Styling

    In addition to the predefined themes, the grid could be further customized by setting some of the available CSS properties. In case you would like to change some of the colors, you need to set a class for the grid first:

    <IgrGrid className="grid"></IgrGrid>
    

    Then set the related CSS properties for that class:

    .grid {
        --ig-grid-filtering-row-text-color: #292826;
        --ig-grid-filtering-row-background: #ffcd0f;
        --ig-grid-filtering-header-text-color: #292826;
        --ig-grid-filtering-header-background: #ffcd0f;
    }
    

    Demo

    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.