# Column Scope

Canonical page: https://www.adaptabletools.com/docs/dev-guide-columns-scope

- Column Scope defines in which columns a given AdapTable feature is applied
- It can comprise named Columns, Data Types, Column Types or a whole Row

Column Scope specifies **where** an AdapTable Feature can be applied.

It sets which columns any given [Adaptable Object](https://www.adaptabletools.com/docs/dev-guide-adaptable-state-initial-state/index.md#adaptable-objects) will be evaluated for.

The [`Column Scope`](https://www.adaptabletools.com/docs/reference/columnscope.md) object has 4 main types of values:

Typically, Scope will include only one of these 4 types

- **All** - This will include every Column in a Row
- **Column(s)** - An array of *ColumnId*s
- **Data Type(s)** - An array of [Data Types](https://www.adaptabletools.com/docs/dev-guide-aggrid-cell-data-types/index.md) (available values are: `text`, `number`, `boolean`, `date`, `textArray` and `numberArray`)
- **Column Type(s)** - An array of strings which specify which [Column Types](https://www.adaptabletools.com/docs/dev-guide-columns-column-types/index.md) to use

## Where Column Scope is Used

Column Scope is used widely in AdapTable in both [Initial Adaptable State](https://www.adaptabletools.com/docs/dev-guide-adaptable-state-initial-state/index.md) sections and [Adaptable Options](https://www.adaptabletools.com/docs/technical-reference-adaptable-options/index.md).

Some of the usage for Column Scope includes:

- [Alerts](https://www.adaptabletools.com/docs/handbook-alerting/index.md)
- [Column Formatting](https://www.adaptabletools.com/docs/handbook-column-formatting/index.md)
- [Custom Sort Comparers](https://www.adaptabletools.com/docs/handbook-custom-sorting/index.md#comparer-function)
- [Export](https://www.adaptabletools.com/docs/handbook-exporting/index.md) (used in [Custom Reports](https://www.adaptabletools.com/docs/handbook-exporting-reports-custom/index.md))  
- [Flashing Cells](https://www.adaptabletools.com/docs/handbook-flashing-cell/index.md)
- [Plus Minus](https://www.adaptabletools.com/docs/handbook-editing-plus-minus/index.md)
- [Shortcuts](https://www.adaptabletools.com/docs/handbook-editing-shortcut/index.md) 

This allows you greater flexibility when creating objects.  For instance you can set:

- one Format Column for all Numeric columns (e.g. Green Font for Positive values)
- a Data Validation Alert for a given set of named columns
- a Display Format for all Columns of a bespoke Column Type (e.g. 'pricing')
- a subset of columns to be exported in a Report

When the object also has an [Expression](https://www.adaptabletools.com/docs/adaptable-ql-expression/index.md) (a Format Column Rule, Flashing Cell Rule, Alert, and so on), use the [$SCOPE function](https://www.adaptabletools.com/docs/adaptable-ql-expression-advanced-scope-function/index.md) to refer to the current column in that Scope.

That lets you write one Expression - e.g. `IS_POSITIVE($SCOPE)` - that applies to every column the Scope covers, instead of naming each `ColumnId`.

## Using Column Scope

The Adaptable UI makes it easy to set the Column Scope of an object that is being created or edited.

### Setting Column Scope in a Settings Panel Wizard

These are the steps involved:

There are usually (depending on the Module) 4 Radio Buttons:

- All Columns - maps to a scope of `All`

- Selected Columns - maps to a scope of `ColumnIds`

- Data Types - maps to a scope of `DataTypes`

- Column Types - maps to a scope of `ColumnTypes`

Clicking the *All Columns* button does not require any extra step.

Typically you will use the [Expression Editor](https://www.adaptabletools.com/docs/ui-expression-editor/index.md) in a future step to create an [Expression](https://www.adaptabletools.com/docs/adaptable-ql-expression/index.md).

Clicking the *Columns* button will display a list of all the Columns in AG Grid.

Click the Columns you want in your Scope - you will see them appear in a list at the bottom.

You can choose to see only the Selected Columns in the wizard.

Clicking the *Data Types* button will display a list of Checkboxes with available [Data Types](https://www.adaptabletools.com/docs/dev-guide-aggrid-cell-data-types/index.md).

This is typically (unless you are using a Module with reduced DataType Scope like [Shortcuts](https://www.adaptabletools.com/docs/handbook-editing-shortcut/index.md)):

- date
- number
- text
- boolean
- textArray
- numberArray

See [Cell Data Types](https://www.adaptabletools.com/docs/dev-guide-aggrid-cell-data-types/index.md) for more details

Clicking the *Column Types* button will display a list of Checkboxes with available Column Types.

This list is derived from the values provided in the `columnTypes` prop in [Column Options](https://www.adaptabletools.com/docs/technical-reference-column/index.md) (which can either supply a list of Column Types or a function that returns a list).

See [Column Types](https://www.adaptabletools.com/docs/dev-guide-columns-column-types/index.md) for detailed information on how to provide and use Column Types

## Configuring Column Scope

It is very straightforward to set Column Scope in [Initial Adaptable State](https://www.adaptabletools.com/docs/dev-guide-adaptable-state-initial-state/index.md):

### Scope: All

To set a Scope of `All` (i.e. the whole row) you need to set 'All' to **true**:

```ts {1}
Scope: { All: true }
```

- This is typically done when the object uses an [Expression](https://www.adaptabletools.com/docs/adaptable-ql-expression/index.md) 
- Essentially it will operate over the whole row rather than individual columns

### Scope: ColumnIds

To set a Scope on one or more Columns, simply provide an array of `ColumnIds` values:

```ts {1}
Scope: { ColumnIds: ['ItemCost', 'Package Cost', 'OrderCost'] }
```

### Scope: Data Types

To set a Scope of one or more [Data Types](https://www.adaptabletools.com/docs/dev-guide-aggrid-cell-data-types/index.md) (e.g. number, text), provide an array of `DataTypes` values:

```ts  {1}
Scope: { DataTypes: ['number'] }
```

### Scope: Column Types

To set a Scope of one or more [Column Types](https://www.adaptabletools.com/docs/dev-guide-columns-column-types/index.md), provide an array of strings that contain available `ColumnTypes`:

```ts  {1}
Scope: { ColumnTypes: ['number-column', 'price', 'calculatedColumn'] }
```

### Scope: Multiple Sections

It is possible - albeit rare - to provide multiple Scope types (e.g. DataType and ColumnIds).

For instance to use [Column Formatting](https://www.adaptabletools.com/docs/handbook-column-formatting/index.md) to format all `date` Columns plus 3 other Columns you could do:

```ts {2,3}
Scope: {
    DataTypes: ['date'],
    ColumnIds: ['country', 'currency', 'counterparty']
},
```

The Column Scope API is in the [Column Scope Technical Reference](https://www.adaptabletools.com/docs/technical-reference-column-scope/index.md)
