# Filter Components

Canonical page: https://www.adaptabletools.com/docs/handbook-column-filter-components

- AdapTable provides 2 main components to allow run-time users to create Column Filters with multiple conditions
  - Filter Form - a popup that contains all the functionality required to manage complex filtering
  - Filter Bar - sits between the Column Header and the first row of the Grid - and designed for quick filtering
- Both components enable the IN filter to be used to select multiple column values

Column Filtering in AdapTable is done via 2 main UI components:
- Filter Form - popup offering comprehensive, multi-condition filtering functionality (also used in ToolPanel)
- Filter Bar - bar underneath the Column Header, designed for quick filtering

## Filter Form

The Adaptable Filter Form provides a way to create powerful Filters with just a few clicks.

Every column in AdapTable will display a bespoke Filter Form.

The Filter Form contains:
- list of available Expression Functions for the Column (based on its data type)
- list of distinct column values (when using the [IN Function](https://www.adaptabletools.com/docs/handbook-column-filter-in-filter/index.md))
- `Add Condition` button to add additional conditions to the Column Filter
- `Clear Filters` button
- `Apply Filter` button (if [Manually Applying Filters](https://www.adaptabletools.com/docs/handbook-column-filter-manually-applying/index.md) is turned on)   

The Filter Form is only displayed for Columns with `filterable` set to _true_ in AG Grid GridOptions

### Filter Form Locations

The AdapTable Filter Form is displayed in 2 places in the Grid:

- As a popup that opens when clicking the Filter button in the [Column Menu](https://www.adaptabletools.com/docs/ui-column-menu/index.md)

- In the _Filters_ Tool Panel in the [AG Grid sidebar](https://www.ag-grid.com/javascript-data-grid/side-bar/) (generally displayed to the right of the grid)

## Filter Bar

The Filter Bar is a custom AdapTable UI Component that replaces AG Grid's Floating Filter.

It is displayed between the Column Header and the first data row in AG Grid.

### Setting up and Displaying the Filter Bar

Set `floatingFilter` to *true* in `GridOptions` for all Columns which should display a Filter Bar.

Either set each column individually:

```ts {6}
export const columnSchema: ColDef[] = [
  {
    field: 'make',
    headerName: 'Make',
    cellDataType: 'text',
    floatingFilter: true,
  }
];
```

or use the `defaultColDef`:

```ts {4}
const gridOptions: GridOptions = {
   defaultColDef: {
    filter: true,
    floatingFilter: true,
  },
} 
```

The Filter Bar is only available if at least **one** column in Grid Options sets this property to *true*

The Filter Bar comprises 2 elements:

- **Filter Dropdown** - sits on the left hand side of the Filter Bar and contains all the System and Custom Filters which have [Scope](https://www.adaptabletools.com/docs/dev-guide-columns-scope/index.md) for that column

- **Input Control** - if the selected filter requires `inputs`, a control appears enabling these to be entered

- The type of the input control varies depending on the **Data Type** of the [Column](https://www.adaptabletools.com/docs/dev-guide-columns-adaptable-column/index.md)
- A TextBox is used for strings, a Date Picker for dates, and a Numeric Editor for numbers

If the selected filter requires no inputs (e.g. `Today`), its name is displayed here instead

### `IN` Function

The `IN` function differs to other filters as it can receive multiple column values.

When this filter is selected, AdapTable changes the input box to 'Select Values', and AdapTable lists the distinct values for the column with a checkbox by each.

Users are then able to provide the inputs to the `IN` function by selecting the checkboxes they require.

See the Guide to the [In Filter](https://www.adaptabletools.com/docs/handbook-column-filter-in-filter/index.md) for more information, including how to display custom values

### Wildcards
Wildcards are available in the Filter Bar to speed up filtering, and reduce mouse usage.

For example, you can type '>' in a numeric input to jump to the `GT` (Greater Than) operator.

The 5 wildcards provided by AdapTable are (the `Operator` column is the key used in `quickFilterWildcards`):

| Wildcard | Operator  | Available Columns |
| -------- | --------- | ----------------- |
| `` = ``  | `EQ`      | Text, Number      |
| `` > ``  | `GT`      | Number            |
| `` < ``  | `LT`      | Number            |
| `` [ ``  | `IN`      | All Columns       |
| `` # ``  | `IN`      | All Columns       |

### `quickFilterWildcards`

Shortcut Keys to activate a Filter Bar filter

Use this property to add or remove the wildcards used in the Filter Bar.

<b>Provide New Wildcards</b>

Users can set new wildcards by supplying the operator name and the wildcard keys (in the form of an array) to trigger it 

```ts {6}
// Set a new wildcard of exclamation for the Not Equals (NEQ) operator
const adaptableOptions: AdaptableOptions = {
  filterOptions: {
    columnFilterOptions: {
      quickFilterWildcards:{
        NEQ: ['!'],
      } 
    }
  }
};
```
<b>Update Wildcards</b>
Users can update wildcards by supplying the operator name and the wildcard keys (in the form of an array) that should replace the existing implementation 

- This is useful if you explicitly want to filter on a cell value, or use in a different way, a wildcard value
- e.g. the '[' wildcard (used for the `IN` filter) is a legitimate character when using the `Regex` filter

```ts {6}
// Keep the '#' wildcard for the IN operator (but remove '[' so we can use in RegEx)
const adaptableOptions: AdaptableOptions = {
  filterOptions: {
    columnFilterOptions: {
      quickFilterWildcards:{
        IN: ['#'],
      } 
    }
  }
};
```
<b>Clear Existing Wildcards</b>
To remove a wildcard shipped by AdapTable simply provide an empty array for that operator.
```ts {6}
// Clear the Wildcards for the IN operator
const adaptableOptions: AdaptableOptions = {
  filterOptions: {
    columnFilterOptions: {
      quickFilterWildcards:{
        IN: [],
      } 
    }
  }
};
```

**Example: Filter Bar Wildcards**

Adding and removing Wildcards in Filter Bar

- This Demo shows how to manage Wildcards in the Filter Bar:
  - an empty array has been provided for `In` - so that neither of the System wildcards for that filter are operable
  - a value of '!' has been provided for the NotEquals filter - so that entering that in a number column will change the filter automatically

- Type '[' or '#' in the `Language` column and see that the `IN` filter does not appear
- Type '!' in `Github Stars` column and note that the filter changes to `NotEquals`

Demo project (Vanilla); the files without a marker are shown below:

```text
src/
  adaptableOptions.ts
  agGridModules.ts     [template]
  columnDefs.ts        [template]
  gridOptions.ts       [template]
  index.ts             [template]
  onAdaptableReady.ts  [template]
  rowData.ts           [template]
  styles.css           [template]
index.html             [template]
package.json           [template]
tsconfig.json          [template]
```

Files marked `[template]` are the same in every demo; see the [demo template](https://www.adaptabletools.com/llms/demo-template.md#vanilla).

**`src/adaptableOptions.ts`**

```ts
import {AdaptableOptions} from '@adaptabletools/adaptable';
import {WebFramework} from './rowData';

export const adaptableOptions: AdaptableOptions<WebFramework> = {
  primaryKey: 'id',
  adaptableId: 'Filter ּBar Wildcards',
  filterOptions: {
    columnFilterOptions: {
      // Remove the System Wildcards for the IN operator
      // Add a '!' for the Not Equals (NEQ) operator
      quickFilterWildcards: {
        NEQ: ['!'],
        IN: [],
      },
    },
  },
  initialState: {
    Dashboard: {
      ModuleButtons: ['ColumnFilter'],
      PinnedToolbars: ['ColumnFilter'],
    },
    StatusBar: {
      StatusBars: [
        {
          Key: 'Center Panel',
          StatusBarPanels: ['Layout', 'ColumnFilter'],
        },
      ],
    },
    Theme: {CurrentTheme: 'dark'},
    Layout: {
      CurrentLayout: 'Standard Layout',
      Layouts: [
        {
          TableColumns: [
            'name',
            'language',
            'github_stars',
            'license',
            'has_projects',
            'has_pages',
            'created_at',
            'has_wiki',
            'updated_at',
            'pushed_at',
            'github_watchers',
            'description',
            'open_issues_count',
            'closed_issues_count',
            'open_pr_count',
            'closed_pr_count',
            'week_issue_change',
          ],
          Name: 'Standard Layout',
          AutoSizeColumns: true,
        },
      ],
    },
  },
};
```

### Hiding the Filter Bar
The Filter Bar can be hidden or made visible, both at design time and run time.
- **Design-time** visibility is provided via the `showQuickFilter` property in [Column Filter Options](https://www.adaptabletools.com/docs/technical-reference-filter/index.md)
### `showQuickFilter`

Whether to display Filter Bar between Column Header and the Grid (provided its been setup)

AdapTable, by default, will display the Filter Bar - provided that one has been set up.
Set this property to *false* if you want a Filter Bar available to your users - but hidden by default.

Hidden Filter Bars can be made visible by selecting `Show Filter Bar` in the [Column Menu](https://www.adaptabletools.com/docs/ui-column-menu/index.md)

```ts {4}
// Hide the Filter Bar (but allow it to be made visible by users)
const adaptableOptions: AdaptableOptions = {
  filterOptions: {
    columnFilterOptions: {
      showQuickFilter: false,
    },
  },
};
``` 

- **Run-time** Filter Bar visibility can be handled in various ways including:
  - Checking / unchecking the `Quick Filter Checkbox` in the [Filter Toolbar](https://www.adaptabletools.com/docs/ui-dashboard-tabs-toolbars/index.md)
  - Checking / unchecking the `Quick Filter Checkbox` in the [Filter Tool Panel](https://www.adaptabletools.com/docs/ui-tool-panel/index.md)
  - Accessing the `Show / Hide Quick Filter Bar` [Column Menu](https://www.adaptabletools.com/docs/ui-column-menu/index.md) Item

- Filter Bar visibility which is changed mid-session is **not** subsequently persisted, as it is not part of [Adaptable State](https://www.adaptabletools.com/docs/dev-guide-adaptable-state/index.md)
- However, you can easily save and restore Filter Bar visibility by using the [Application](https://www.adaptabletools.com/docs/dev-guide-adaptable-state-custom/index.md) section of [Adaptable State](https://www.adaptabletools.com/docs/dev-guide-adaptable-state/index.md)

#### Hiding Filter Bar Elements

As well as hiding the Filter Bar entirely, the dropdown on the left of each Column's Floating Bar can also be hidden.

- This is often the case for Boolean columns or when screen real estate is very tight
- This can be hidden on a column by column basis if required

This is achieved using the `hideQuickFilterDropdown` function in the `columnFilterOptions` section of Filter Options.

### `hideQuickFilterDropdown`

Don't show the Filter Bar Dropdown for some Columns

For those columns where the filter dropdown might not be required in the Filter Bar, the `hideQuickFilterDropdown` function can be used.

The [`AdaptableColumnContext`](https://www.adaptabletools.com/docs/reference/adaptablecolumncontext.md) object contains the [Adaptable Column](https://www.adaptabletools.com/docs/dev-guide-columns-adaptable-column/index.md) being filtered.

```ts {4,5,6}
// Don't show the Dropdown in Filter Bar for Boolean columns
const adaptableOptions: AdaptableOptions = {
  filterOptions: {
    columnFilterOptions: {
      hideQuickFilterDropdown: (adaptableColumnContext) => {
        return adaptableColumnContext.column.dataType == 'boolean';
      },
    },
  },
};
``` 

### Filter Bar Debounce

By default AdapTable will apply Filters every 250ms in response to user entry in the Filter Bar.

Where this is too quick, e.g. if running Filters on the Server and less frequent Filtering is required, the `quickFilterDebounce` property in Filter Options can be used.

This differs from AdapTable's automatic post-edit filter pass described in [Filtering when Data Changes](https://www.adaptabletools.com/docs/handbook-column-filter-configuring/index.md)

### `quickFilterDebounce`

Time to wait before applying the Filter after entering a value

By default AdapTable will wait 250ms (1/4 of a second) before applying the Filter after a user enters text in the Filter Bar.

This ensures speedy filtering while allowing users to type quickly.

Use this property to set a different throttle value if required:

```ts {4}
// Wait a second before Filtering the grid after the user updates the Filter Bar
const adaptableOptions: AdaptableOptions = {
  filterOptions: {
    columnFilterOptions: {
      quickFilterDebounce: 1000,
    },
  },
};
``` 

**Example: Filter Bar Configuration**

Configuring Filters using Filter Options

- This Demo illustrates a [Column Filter Option](https://www.adaptabletools.com/docs/technical-reference-filter/index.md) for configuring the Filter Bar:
  - an implementation provided for `hideQuickFilterDropdown` property so that the dropdown does not appear in Boolean columns

Demo project (Vanilla); the files without a marker are shown below:

```text
src/
  adaptableOptions.ts
  agGridModules.ts     [template]
  columnDefs.ts        [template]
  gridOptions.ts       [template]
  index.ts             [template]
  onAdaptableReady.ts  [template]
  rowData.ts           [template]
  styles.css           [template]
index.html             [template]
package.json           [template]
tsconfig.json          [template]
```

Files marked `[template]` are the same in every demo; see the [demo template](https://www.adaptabletools.com/llms/demo-template.md#vanilla).

**`src/adaptableOptions.ts`**

```ts
import {
  AdaptableOptions,
  AdaptableColumnContext,
} from '@adaptabletools/adaptable';
import {WebFramework} from './rowData';

export const adaptableOptions: AdaptableOptions<WebFramework> = {
  primaryKey: 'id',
  adaptableId: 'Filter ּBar Options',
  filterOptions: {
    columnFilterOptions: {
      hideQuickFilterDropdown: (context: AdaptableColumnContext) => {
        return context.column.dataType == 'boolean';
      },
    },
  },
  initialState: {
    Dashboard: {
      ModuleButtons: ['ColumnFilter'],
      PinnedToolbars: ['ColumnFilter'],
    },
    StatusBar: {
      StatusBars: [
        {
          Key: 'Center Panel',
          StatusBarPanels: ['Layout', 'ColumnFilter'],
        },
      ],
    },
    Theme: {CurrentTheme: 'dark'},
    Layout: {
      CurrentLayout: 'Standard Layout',
      Layouts: [
        {
          TableColumns: [
            'name',
            'language',
            'github_stars',
            'license',
            'has_projects',
            'has_pages',
            'created_at',
            'has_wiki',
            'updated_at',
            'pushed_at',
            'github_watchers',
            'description',
            'open_issues_count',
            'closed_issues_count',
            'open_pr_count',
            'closed_pr_count',
            'week_issue_change',
          ],
          Name: 'Standard Layout',
          AutoSizeColumns: true,
        },
      ],
    },
  },
};
```

### Filter Bar Height

AdapTable will set the height of the Filter Bar to the AG Grid default.

If that is not required, the height can be set using the `quickFilterHeight` property in Filter Options:

### `quickFilterHeight`

Sets height of Filter Bar (if not provided AG Grid default is used)

By default AdapTable will allow AG Grid to set the height of the Filter Bar (by setting its Floating Filter).

Use this property to set the height explicitly:

```ts {4}
// Explicitly set the height of the Filter Bar
const adaptableOptions: AdaptableOptions = {
  filterOptions: {
    columnFilterOptions: {
      quickFilterHeight: 80,
    },
  },
};
``` 

## Other Filter Components

In addition to the 2 main Filter Components, AdapTable provides 4 additional filter-related components:

- [Dashboard Toolbar](https://www.adaptabletools.com/docs/ui-dashboard/index.md#tabs-and-toolbars)
- [Tool Panel](https://www.adaptabletools.com/docs/ui-tool-panel/index.md)
- [Status Bar Panel](https://www.adaptabletools.com/docs/ui-status-bar/index.md)
- [Settings Panel](https://www.adaptabletools.com/docs/ui-settings-panel/index.md)

Each of these components allow run-time Users to:
- see which Column Filters are active
- clear Column Filters
- Suspend / Reactivate Columns
- Open the Filter Form (to edit Column Filters)

### FAQ

**Can we change the Filter Bar filter without using the Dropdown**
Yes, wildcards are available for the more commonly used filters

**The Filter Bar is disabled, why is that?**
Check that you have not set [Manually Applying Filters](https://www.adaptabletools.com/docs/handbook-column-filter-manually-applying/index.md) as this will disable the Filter Bar
