# Configuring Column Filters

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

- Column Filtering in AdapTable includes advanced features for more demanding use cases
- These are primarily available in [Column Filter Options](https://www.adaptabletools.com/docs/technical-reference-filter/index.md) and allow developers to configure Filtering as needed

AdapTable provides many configuration options which allow developers to set up Column Filtering to meet precise requirements.

Most of these are available in the [Column Filter Options](https://www.adaptabletools.com/docs/technical-reference-filter/index.md) section of Adaptable Options.

- This page lists some general Column Filtering options
- See [Filter Components](https://www.adaptabletools.com/docs/handbook-column-filter-components/index.md) and [In Filter](https://www.adaptabletools.com/docs/handbook-column-filter-in-filter/index.md) for options to configure those UI Filter Components

## Using AG Grid Filtering

By default AdapTable provides its own Filter controls instead of those provided by AG Grid.

This is the only place in AdapTable where it provides alternative, rather than complementary, functionality

We do this because we think that AdapTable offers a richer, more intuitive and more configurable set of Filters.

AdapTable provides Filters in Layouts meaning you can save,and easily switch between, different Filter sets.

- An additional benefit is that AdapTable allows users to access Grid Filter and Column Filters simultaneously
- This is not possible using the AG Grid equivalents, where you need to choose between them

In the rare use case where AG Grid's filters are preferred, they can easily be turned on by setting `useAdaptableFiltering` to false in Filter Options.

- This does not remove AdapTable Filtering logic, e.g the API functions will all still operate
- However it does hide all AdapTable Filtering UI controls so they cannot be accessed accidentally

### `useAdaptableFiltering`

Turns off AdapTable Filtering and uses AG Grid Filters

Use this property to specify usage of AG Grid's Filters (in preference to those provided by AdapTable).

```ts {3}
// Use AG Grid Filters and hide AdapTable's filters
const adaptableOptions: AdaptableOptions = {
  filterOptions: {
    useAdaptableFiltering: false,
  },
};
```

**Example: Using AG Grid Filtering**

Selecting AG Grid Filters instead of AdapTable

- In this example we have turned off AdapTable Filtering (and use AG Grid's instead)
- As a result we see AG Grid's Floating Filter (under the Column Headers), Filter Form and Filters Tool Panel
- Additionally Column Filters and Grid Filter are absent from the Layout and all Adaptable Filtering controls (toolpanels, toolbars etc) are missing

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: 'AG Grid Filtering Demo',
  filterOptions: {
    useAdaptableFiltering: false,
  },
  initialState: {
    StatusBar: {
      StatusBars: [
        {
          Key: 'Center Panel',
          StatusBarPanels: ['Layout'],
        },
      ],
    },
    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',
            'week_issue_change',
          ],
          Name: 'Standard Layout',
          AutoSizeColumns: true,
        },
      ],
    },
  },
};
```

## Non Filterable Rows

By default all data rows in AdapTable will be evaluated in Column Filtering.

Occasionally, the use case arises where some rows should **always** be present and never subject to filtering.

This can be configured using the `isRowFilterable` property in [Filter Options](https://www.adaptabletools.com/docs/technical-reference-filter/index.md).

### `isRowFilterable`

Configures which Data Rows cannot be filtered

By default AdapTableQL will evaluate every row in the Grid when it applies a Column Filter.

Use this property to specify which rows should never be filtered.

```ts
isRowFilterable?: (context: IsRowFilterableContext) => boolean;
```

The property takes the form of a function that receives an `IsRowFilterableContext` object and returns a boolean.

The [`IsRowFilterableContext`](https://www.adaptabletools.com/docs/reference/isrowfilterablecontext.md) is defined as follows:

| Property | Type | Description |
| --- | --- | --- |
| [data](https://www.adaptabletools.com/docs/reference/isrowfilterablecontext.md#data) | `TData` | The data in the Row Node |
| [rowNode](https://www.adaptabletools.com/docs/reference/isrowfilterablecontext.md#rownode) | `IRowNode` | The Row Node about to be evaluated |
| [adaptableContext](https://www.adaptabletools.com/docs/reference/isrowfilterablecontext.md#adaptablecontext) | `any` | Custom application Context provided in `AdaptableOptions.adaptableContext` |

```ts {3}
// Don't filter the first row, or any row where Language is HTML
const adaptableOptions: AdaptableOptions = {
  filterOptions: {
    isRowFilterable: (context: IsRowFilterableContext) => {
      return !context.rowNode.firstChild && context.data['language'] !== 'HTML';
    },
  },
};
```

**Example: Non-Filterable Rows**

Configuring which rows cannot be filtered

- In this example we provide an implementation for `isRowFilterable` property, so these rows are **never** filtered:
  - the first row in the Grid
  - any row where `Language` is 'HTML' 
- We filter the `Language` column on 'TypeScript' but still see "JavaScript" for the `Language` column in first row, and see 'HTML' as those rows are excluded from filtering

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,
  IsRowFilterableContext,
} from '@adaptabletools/adaptable';
import {WebFramework} from './rowData';

export const adaptableOptions: AdaptableOptions<WebFramework> = {
  primaryKey: 'id',
  adaptableId: 'Non Filterable Rows',
  filterOptions: {
    isRowFilterable: (context: IsRowFilterableContext) => {
      return !context.rowNode.firstChild && context.data['language'] !== 'HTML';
    },
  },
  initialState: {
    StatusBar: {
      StatusBars: [
        {
          Key: 'Center Panel',
          StatusBarPanels: ['ColumnFilter'],
        },
      ],
    },
    Theme: {CurrentTheme: 'dark'},
    Layout: {
      CurrentLayout: 'Filtered Layout',
      Layouts: [
        {
          Name: 'Filtered Layout',
          TableColumns: [
            'name',
            'language',
            'github_watchers',
            'github_stars',
            'has_wiki',
            'open_issues_count',
            'closed_issues_count',
            'open_pr_count',
            'closed_pr_count',
            'has_projects',
            'has_pages',
            'week_issue_change',
            'updated_at',
            'pushed_at',
            'description',
          ],
          ColumnFilters: [
            {
              ColumnId: 'language',
              Expression: '[language] = "Typescript"',
            },
          ],
          AutoSizeColumns: true,
        },
      ],
    },
  },
};
```

## Filtering on Special Columns

By default, AdapTable allows all [Calculated Columns](https://www.adaptabletools.com/docs/handbook-calculated-column/index.md) and [FreeText Columns](https://www.adaptabletools.com/docs/handbook-freetext-column/index.md) to be filterable.

This behaviour can be changed via the `enableFilterOnSpecialColumns` property in [Filter Options](https://www.adaptabletools.com/docs/technical-reference-filter/index.md).

### `enableFilterOnSpecialColumns`

Allows filtering on Calculated and FreeText columns

Setting this property to _false_ will disallow filtering on **all** Calculated and Free Text Columns.

This will **override** the `Filterable` property value in the Calculated Column or Free Text Column definition 

```ts {3}
// Don't allow Calculated or Free Text Columns to be filterable
const adaptableOptions: AdaptableOptions = {
  filterOptions: {
    enableFilterOnSpecialColumns: false,
  },
};
```

If this property is `true`, you can still set filtering to `false` on a per Calculated / Free Text Column basis

```ts {4,16}
// Allow Calculated & Free Text Columns to be filterable by default
const adaptableOptions: AdaptableOptions = {
  filterOptions: {
    enableFilterOnSpecialColumns: true,
  },
};

// But override at Calculated Column level
CalculatedColumn: {
  CalculatedColumns: [
    {
      ColumnId: 'total_pr_count',
      Expression: '[open_pr_count] + [closed_pr_count]',
      CalculatedColumnSettings: {
        DataType: 'number',
        Filterable: false,
      },
    }],
},
```

## Clearing Column Filters on Startup

AdapTable always saves previously applied Column Filters (and the Grid Filter) into AdapTable State (via the Current Layout).

It will then automatically re-apply these Filters when the Application is reloaded.

If this behaviour is not desired, set the `clearFiltersOnStartUp` property in [Filter Options](https://www.adaptabletools.com/docs/technical-reference-filter/index.md) to _true_.

### `clearFiltersOnStartUp`

Clear any Column or Grid Filters applied in previous session when Application re-starts

AdapTable saves all [User State](https://www.adaptabletools.com/docs/dev-guide-adaptable-state/index.md) to either local or remote storage, including Column Filters.

It then re-applies any persisted Columns Filters when the application re-starts.

Setting this property to _true_ will remove any Column Filters in Adaptable State from the previous session, and display a non-filtered AG Grid instance.

```ts {3}
// Clear any previously set Column or Grid Filters when AdapTable re-starts
const adaptableOptions: AdaptableOptions = {
  filterOptions: {
    clearFiltersOnStartUp: true,
  },
};
```

The `clearQuickSearchOnStartUp` property in [Quick Search Options](https://www.adaptabletools.com/docs/technical-reference-quick-search/index.md) will clear a saved [Quick Search](https://www.adaptabletools.com/docs/handbook-quick-search/index.md)

## Indicating Filtered Columns

AdapTable distinctively renders the Column Header for any currently filtered columns.

This is particularly helpful when users restart the application, unaware that filters were persisted

If this is not desired behaviour, set the `indicateFilteredColumns` property to _false_.

- AG Grid will still indicate filtered Columns by providing a different filter icon in the Column Header
- You will need to change the AG Grid css to handle this

### `indicateFilteredColumns`

Style Column Header to visually identify which Columns are currently filtered

Stops AdapTable from making the Header for currently filtered columns distinctive.

```ts {5}
// Don't distinctively show Filtered Columns
const adaptableOptions: AdaptableOptions = {
  filterOptions: {
    columnFilterOptions: {
      indicateFilteredColumns: false,
    },
  },
};
```

## Column Filter Changed Event

AdapTable fires the [Column Filter Changed Event](https://www.adaptabletools.com/docs/technical-reference-filter/index.md) whenever a Column Filter editor or persisted Filter changes.

Use `isApplied` to react only when the Layout Filter (and grid) actually updates. `ColumnFilterApplied` still fires in that case.

This is often used when wanting to [evaluate expressions on the Server](https://www.adaptabletools.com/docs/adaptable-server-evaluation/index.md)

**Example: Column Filter Changed Event**

Listening to Column Filter Changed Event

- In this example we listen to the [Column Filter Changed Event](https://www.adaptabletools.com/docs/technical-reference-filter/index.md) and output the Event's info to the console when `isApplied` is true

- Create a Column Filter and inspect the Console to see the output from the Event

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
  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: 'Column Filter Applied Event',
  initialState: {
    Dashboard: {
      ModuleButtons: ['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',
            'week_issue_change',
          ],
          Name: 'Standard Layout',
          AutoSizeColumns: true,
        },
      ],
    },
  },
};
```

**`src/onAdaptableReady.ts`**

```ts
import {
  AdaptableReadyInfo,
  ColumnFilterChangedInfo,
} from '@adaptabletools/adaptable';

export const onAdaptableReady = ({adaptableApi}: AdaptableReadyInfo) => {
  adaptableApi.eventApi.on(
    'ColumnFilterChanged',
    (columnFilterChangedInfo: ColumnFilterChangedInfo) => {
      if (columnFilterChangedInfo.isApplied) {
        console.log('Column Filter Changed', columnFilterChangedInfo);
      }
    }
  );
};
```

## Show Date Picker

Date Columns use AdapTable's Date Picker in Column Filter and Grid Filter controls by default.

Set `showDatePicker` to _false_ in Filter Options to use a plain date input instead.

### `showDatePicker`

Show a Date Picker (or Date Input) in Filter controls

Set this to *false* to use a date input in Column Filter and Grid Filter date controls.

```ts {3}
const adaptableOptions: AdaptableOptions = {
  filterOptions: {
    showDatePicker: false,
  },
};
```

**Example: Date Input instead of Date Picker**

Using a date input in Filter controls

- In this example `showDatePicker` is set to _false_
- Date Filter controls therefore show a date input rather than the Date Picker

- Open the Column Filter for the `Created` or `Updated` column and note that a date input is displayed

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: 'Show Date Picker Demo',
  filterOptions: {
    showDatePicker: false,
  },
  initialState: {
    StatusBar: {
      StatusBars: [
        {
          Key: 'Center Panel',
          StatusBarPanels: ['Layout', 'ColumnFilter'],
        },
      ],
    },
    Theme: {CurrentTheme: 'dark'},
    Layout: {
      CurrentLayout: 'Standard Layout',
      Layouts: [
        {
          TableColumns: [
            'name',
            'created_at',
            'updated_at',
            'pushed_at',
            'language',
            'github_stars',
          ],
          Name: 'Standard Layout',
          AutoSizeColumns: true,
        },
      ],
    },
  },
};
```
