# Shortcuts

Canonical page: https://www.adaptabletools.com/docs/handbook-editing-shortcut

- Shortcuts ensure that numeric data is edited accurately and quickly in AG Grid
- They allow users to avoid "fat finger" issues when editing data quickly
- They consist of 4 main elements:
  - Which Columns can accept the Shortcut
  - What key will apply the Shortcut
  - What Operation will be applied when the Key is pressed
  - What Value will be applied
- This allows users to provide a Shortcut where clicking 'M' in a Price column will multiply by 1000

Shortcuts ensure that numeric data is edited accurately and quickly in AG Grid.

Each Shortcut consists of an alphabet keystroke which, when entered into a numeric cell editor, applies a mathematical operation using the existing cell contents.

A Shortcut can be limited to specific Layouts via [Layout Extensions](https://www.adaptabletools.com/docs/handbook-layouts-extending/index.md)

**Example: Using Shortcuts**

Editing data quickly using custom Shortcuts

- Two Shortcuts in Initial State (see `adaptableOptions.ts`):
  - **`K`** on all numeric columns — multiply by 1,000
  - **`P`** on `github_stars` — add 1

- Double-click a numeric cell, start editing, and type **`K`** to multiply by 1,000
- Double-click `github_stars`, start editing, and type **`P`** to add 1

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: 'Shortcuts',

  initialState: {
    Dashboard: {
      ModuleButtons: ['Shortcut'],
    },
    Theme: {CurrentTheme: 'dark'},
    Shortcut: {
      Shortcuts: [
        {
          Name: 'shortcut-K-multiply-1000',
          Scope: {DataTypes: ['number']},
          ShortcutKey: 'K',
          ShortcutOperation: 'Multiply',
          ShortcutValue: 1000,
        },
        {
          Name: 'shortcut-P-add-1',
          Scope: {ColumnIds: ['github_stars']},
          ShortcutKey: 'P',
          ShortcutOperation: 'Add',
          ShortcutValue: 1,
        },
      ],
    },
    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,
        },
      ],
    },
  },
};
```

## Applying Shortcuts

Shortcuts are applied by pressing the key identified as the `ShortcutKey` in a Shortcut in a numeric cell editor.

AdapTable will check if the key press is a valid Shortcut and, if it is, perform the mathematical calculation.

For example, a Shortcut of `k` with an operation of `Multiply by 1000` would convert an initial cell value of `5` into `5,000` if the `k` key is pressed on the keyboard.

## Creating Shortcuts

Shortcuts can be managed at runtime via the Shortcut section of the [Settings Panel](https://www.adaptabletools.com/docs/ui-settings-panel/index.md).

This lists the details of all existing Shortcuts in Adaptable State together with options to:

- *create* (via the Shortcut Wizard)
- *edit* (via the Shortcut Wizard)
- *delete*
- *suspend*
- *share* (if Team Sharing is running)

### Using the Shortcut Wizard

There are 5 stages to defining a Shortcut:

Choose a unique name for the Shortcut.

Either choose which numeric columns can use the Shortcut.

Or set the `Number` DataType so that **all** numeric columns can use the Shortcut

See [Guide to Column Scope](https://www.adaptabletools.com/docs/dev-guide-columns-scope/index.md) for more on this commonly used object

Choose which keyboard key will trigger the Shortcut when it is entered into a (correctly scoped) numeric cell.

Specify which mathematical operation will be used by AdapTable when the Shortcut is applied.

Available values are: `Add`, `Subtract`, `Multiply`, `Divide`

Set the numeric value that will be used in conjunction with the current cell value and the mathematical operation to update the cell.

Shortcuts with an Entitlement of `ReadOnly` can be applied but Users cannot manage or suspend them.

## Configuring Shortcuts

Shortcuts can be provided at design-time through [Shortcut Initial Adaptable State](https://www.adaptabletools.com/docs/technical-reference-editing/index.md).

### Providing Shortcuts in Initial Adaptable State

Choose a unique `Name` for each entry in `Shortcut.Shortcuts`.

Specify which numeric columns can use the Shortcut, or set `DataTypes: ['number']` to include **all** numeric columns.

See [Guide to Column Scope](https://www.adaptabletools.com/docs/dev-guide-columns-scope/index.md) for more on this commonly used object

Set `ShortcutKey` — the letter entered in the cell editor to trigger the Shortcut.

The key must be a letter of the alphabet.

Set `ShortcutOperation` to `Add`, `Subtract`, `Multiply`, or `Divide`.

Set `ShortcutValue` — the numeric operand used with the current cell value and the operation.

This property must be numeric.

```ts [[1, 5, "Name"], [1, 12, "Name"], [2, 6, "Scope"], [2, 13, "Scope"], [3, 7, "ShortcutKey"], [3, 14, "ShortcutKey"], [4, 8, "ShortcutOperation"], [4, 15, "ShortcutOperation"], [5, 9, "ShortcutValue"], [5, 16, "ShortcutValue"]]
const initialState: InitialState = {
  Shortcut: {
    Shortcuts: [
      {
        Name: 'Shortcut-K-1',
        Scope: { DataTypes: ['number'] },
        ShortcutKey: 'K',
        ShortcutOperation: 'Multiply',
        ShortcutValue: 1000,
      },
      {
        Name: 'Shortcut-P-1',
        Scope: { ColumnIds: ['github_stars'] },
        ShortcutKey: 'P',
        ShortcutOperation: 'Add',
        ShortcutValue: 1,
      },
    ],
  },
};
```

## Shortcuts in Row Forms

[Row Forms](https://www.adaptabletools.com/docs/handbook-row-form/index.md) are dynamically-created by AdapTable, designed for safe, controlled AG Grid data editing.

Any defined Shortcuts will **also** be operative in the numeric input in the Row Form.

**Example: Shortcuts in Row Forms**

Shortcuts are available also in Row Forms

- This demo has a Shortcut defined for `numeric` columns - multiply by 1 Million when **M** is clicked
- An `Edit` Action Column command opens an Edit [Row Form](https://www.adaptabletools.com/docs/handbook-row-form/index.md); the same Shortcut works in that form

- Click **Edit** on a row to open the form
- In a numeric field, type **`M`** and note how the value is multiplied by 1,000,000

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: 'Shortcuts in Row Forms',
  actionColumnOptions: {
    actionColumns: [
      {
        columnId: 'action',
        friendlyName: 'Edit',
        controls: [{type: 'command', command: 'edit'}],
      },
    ],
  },
  initialState: {
    Dashboard: {
      ModuleButtons: ['Shortcut'],
    },
    Theme: {CurrentTheme: 'dark'},
    Shortcut: {
      Shortcuts: [
        {
          Name: 'shortcut-M-multiply-1000000',
          Scope: {DataTypes: ['number']},
          ShortcutKey: 'M',
          ShortcutOperation: 'Multiply',
          ShortcutValue: 1000000,
        },
      ],
    },
    Layout: {
      CurrentLayout: 'Standard Layout',
      Layouts: [
        {
          TableColumns: [
            'action',
            '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,
        },
      ],
    },
  },
};
```

### FAQ

**Can we apply shortcuts on non-numeric columns?**
No, Shortcuts only work for numeric columns. 

**Can we apply shortcuts on multiple columns simultaneously?**
No, Shortcuts work by intercepting a cell edit and only one cell in AG Grid can be edited at a time. 
Use [Smart Edit](https://www.adaptabletools.com/docs/handbook-editing-smart-edit/index.md) or [Bulk Update](https://www.adaptabletools.com/docs/handbook-editing-bulk-update/index.md) to update multiple cells.

**Can I use Shortcut to bypass Data Validation?**
No, Shortcuts will not be allowed by AdapTable if the result breaks a Data Validation Rule.

**Do Shortcuts operate in Row Forms?**
Yes you can use Shortcuts while editing data using a [Row Form](https://www.adaptabletools.com/docs/handbook-row-form/index.md)
