# Plus Minus

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

- Plus / Minus increments / decrements numeric cells when the  `+` or `-` keys are pressed
- Users can set the amount by which the Cell will change
- And specify a Nudge Rule which defines whether the Nudge should be applied

Plus / Minus updates **editable, numeric cells** quickly and safely in response to a single keyboard input:

This is ideal for situations where data needs to be edited incredibly quickly (e.g. if marking to market)

- the `+` keyboard key will cause an increment of the cell's value
- the `-` keyboard key will cause a decrement of the cell's value

It is possible to configure different keyboard keys that will trigger the Nudge (see below)

Plus Minus uses **Nudge Rules** - provided by users - which specify:

- **where** to apply the Nudge
- the **amount** by which to increment or decrement the cell
- **when** to apply the Nudge - by providing an optional Rule

- Ensure that the `CellSelectionModule` has been provided in [AG Grid Modules](https://www.adaptabletools.com/docs/getting-started-aggrid-modules/index.md)
- Additionally make sure that the `cellSelection` property in AG Grid GridOptions is not set to *false* or *null*

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

## Applying Plus Minus

Plus / Minus is applied when the user presses the `+` or `-` keys in numeric cells which are in a Nudge Rule scope.

AdapTable will automatically increment or decrement the cell by the Rule's Nudge Value.

**Example: Using Plus/Minus**

Nudging numeric cells using Plus Minus

- This demo has 2 Plus / Minus Rules defined 
  - Nudges in the `GitHub Stars` column change the value by 100
  - Nudges in the `GitHub Watchers` column change the value by 200

- Select a cell in the `github_stars` or `github_watchers` column and press `+` or `-`

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: 'Plus-Minus',
  initialState: {
    Theme: {CurrentTheme: 'dark'},
    PlusMinus: {
      PlusMinusNudges: [
        // Nudge github_stars by 100
        {
          Name: 'github-stars-nudge-100',
          Scope: {
            ColumnIds: ['github_stars'],
          },
          NudgeValue: 100,
        },
        // Nudge github_watchers by 200
        {
          Name: 'github-watchers-nudge-200',
          Scope: {
            ColumnIds: ['github_watchers'],
          },
          NudgeValue: 200,
        },
      ],
    },
    Layout: {
      CurrentLayout: 'Standard Layout',
      Layouts: [
        {
          TableColumns: [
            'name',
            'language',
            'github_stars',
            'license',
            'github_watchers',
            'has_projects',
            'has_pages',
            'created_at',
            'has_wiki',
            'updated_at',
            'pushed_at',
            'week_issue_change',
          ],
          Name: 'Standard Layout',
          AutoSizeColumns: true,
        },
      ],
    },
    FlashingCell: {
      FlashingCellDefinitions: [
        {
          Name: 'flashingCell-github',
          Scope: {
            ColumnIds: ['github_stars', 'github_watchers'],
          },
          Rule: 'ANY_CHANGE()',
        },
      ],
    },
  },
};
```

## Plus Minus Rules

It is possible to add a Rule to a Plus / Minus Definition.

The Rule is a standard [Boolean Expression](https://www.adaptabletools.com/docs/adaptable-ql-expression/index.md) evaluated by [AdapTableQL](https://www.adaptabletools.com/docs/adaptable-ql-expression/index.md)

This sets that the Plus / Minus is only applied by AdapTable if the Rule is evaluated as true.

- It is also possible to set 2 (or more) Nudge Definitions one with a Rule, and another without a Rule
- The default Nudge Definition will be applied only if all Rules have been evaluated and returned *false*

**Example: Using Plus/Minus Rules**

Applying custom Plus Minus rules

- This demo has 3 Plus / Minus Rules defined, all for the `GitHub Stars` column:
  - Nudge by 500 if the value for the `Language` column in the Row is *TypeScript*
  - Nudge by 250 if the value for the `Language` column in the Row is *HTML*
  - Nudge by 10 in all other cases (the default value - when no Rule is applied)

- Select a cell in the `github_stars` column and press `+` or `-`
- If `language` is *TypeScript* it nudges by 500; if *HTML* by 250; otherwise by 10

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: 'Plus-Minus',
  initialState: {
    Theme: {CurrentTheme: 'dark'},
    PlusMinus: {
      PlusMinusNudges: [
        // Nudge github_stars by 500 when language is TypeScript
        {
          Name: 'github-stars-nudge-500',
          Scope: {
            ColumnIds: ['github_stars'],
          },
          Rule: '[language] = "TypeScript"',
          NudgeValue: 500,
        },
        // Nudge github_stars by 250 when language is HTML
        {
          Name: 'github-stars-nudge-250',
          Scope: {
            ColumnIds: ['github_stars'],
          },
          Rule: '[language] = "HTML"',
          NudgeValue: 250,
        },
        // Nudge github_stars by 10 in all other cases
        {
          Name: 'github-stars-nudge-10',
          Scope: {
            ColumnIds: ['github_stars'],
          },
          NudgeValue: 10,
        },
      ],
    },
    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,
        },
      ],
    },
    FlashingCell: {
      FlashingCellDefinitions: [
        {
          Name: 'flashingCell-github_stars',
          Scope: {
            ColumnIds: ['github_stars'],
          },
          Rule: 'ANY_CHANGE()',
        },
      ],
    },
  },
};
```

## Custom Plus Minus Keys

By default Plus Minus Nudges are triggered when the user clicks "+" or "-" keys in the keyboard.

However its possible to override these default keys and specify different trigger keys.

This can be provided in 2 ways:

| Scope         | Configuration                                                                                                                                            |
| ------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Global**    | Using `incrementKey` and `decrementKey` props in `plusMinusOptions` (in [Edit Options](https://www.adaptabletools.com/docs/technical-reference-editing/index.md)) |
| **Per Nudge** | Configuring specific `IncrementKey` and `DecrementKey` values on the Plus Minus object                                                                   |

It is also possible to provide combinations of key strokes e.g `Ctrl + I` or `Shift, Alt + D`

The order of evaluation, when checking whether a Nudge Rule has been invoked, is:

- first, any specific keys provided in a Nudge Rule
- next any bespoke global PlusMinusOptions values provided at design time
- finally the default AdapTable Options values specified by AdapTable

- This allows you to provide 2 Plus Minus Nudges for all columns (without needing to specify a Rule)
- For instance you configure "x" and "y" to increment all numeric columns by 10 and 20 respectively

**Example: Custom Plus/Minus Keys**

Configuring Custom Plus / Minus Keys

- In this example we have changed the defaults keys to increment and decrement in 3 ways:
  - We globally set default keys of `u` and `d` in Plus Minus Options — nudge `github_watchers`
  - Per-nudge keys `f` and `j` on the `github_stars` rule
  - Per-nudge keys `ctrl+I` and `ctrl+D` on the `week_issue_change` rule

- Type `u` or `d` in `github_watchers` and see the cell value change
- Type `f` or `j` in `github_stars` and see the cell value change
- Type `Ctrl+I` or `Ctrl+D` in `week_issue_change` and see the cell value change

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: 'Plus-Minus Custom Keys',
  editOptions: {
    plusMinusOptions: {
      incrementKey: 'u',
      decrementKey: 'd',
    },
  },
  initialState: {
    Theme: {CurrentTheme: 'dark'},
    PlusMinus: {
      PlusMinusNudges: [
        // Nudge week_issue_change by 10 using increment keys 'Ctrl + I' and decrement keys 'Ctrl + D'
        {
          Name: 'week_issue_change-nudge-10',
          Scope: {
            ColumnIds: ['week_issue_change'],
          },
          IncrementKey: 'Ctrl + I', // instead of '+'
          DecrementKey: 'Ctrl + D', // instead of '-'
          NudgeValue: 10,
        },
        // Nudge github_stars by 100 using increment key 'f' and decrement key 'j'
        {
          Name: 'github-stars-nudge-100',
          Scope: {
            ColumnIds: ['github_stars'],
          },
          IncrementKey: 'f', // instead of '+'
          DecrementKey: 'j', // instead of '-'
          NudgeValue: 100,
        },
        // Nudge github_watchers by 200 using increment keys defined in PlusMinusOptions
        {
          Name: 'github-watchers-nudge-200',
          Scope: {
            ColumnIds: ['github_watchers'],
          },
          NudgeValue: 200,
        },
      ],
    },
    Layout: {
      CurrentLayout: 'Standard Layout',
      Layouts: [
        {
          TableColumns: [
            'name',
            'language',
            'github_stars',
            'license',
            'github_watchers',
            'has_projects',
            'week_issue_change',
            'has_pages',
            'created_at',
            'has_wiki',
            'updated_at',
            'pushed_at',
          ],
          Name: 'Standard Layout',
          AutoSizeColumns: true,
        },
      ],
    },
    FlashingCell: {
      FlashingCellDefinitions: [
        {
          Name: 'flashingCell-number',
          Scope: {
            DataTypes: ['number'],
          },
          Rule: 'ANY_CHANGE()',
        },
      ],
    },
  },
};
```

## Keyboard Shortcut Combinations

Trigger keys are not limited to single characters: both the global `incrementKey` / `decrementKey` and the per-Nudge `IncrementKey` / `DecrementKey` also accept **keyboard shortcut combinations**.

A combination uses `+` as the glue between its parts, for example `shift+Enter` or `ctrl+ArrowDown`. The supported modifiers are:

| Modifier | Token   |
| -------- | ------- |
| Control  | `ctrl`  |
| Command  | `cmd`   |
| Alt      | `alt`   |
| Shift    | `shift` |

- The default single keys (`+` and `-`) continue to work exactly as before
- A single character is always treated as a literal key, never as a combination

Because `+` is the glue between parts, it cannot itself be combined with modifiers (use it as a standalone key)

**Example: Plus/Minus Key Combinations**

Triggering Plus / Minus Nudges with keyboard shortcut combinations

- In this example the trigger keys are keyboard shortcut combinations rather than single characters:
  - We globally set `shift+Enter` / `shift+Backspace` in Plus Minus Options — nudge `github_watchers`
  - Per-nudge `ctrl+ArrowUp` / `ctrl+ArrowDown` on `github_stars`

- Select a cell in `github_watchers` and press `Shift+Enter` or `Shift+Backspace`
- Select a cell in `github_stars` and press `Ctrl+ArrowUp` or `Ctrl+ArrowDown`

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: 'Plus-Minus Combination Keys',
  editOptions: {
    plusMinusOptions: {
      // Global trigger keys can be keyboard shortcut combinations.
      // `+` is the glue between parts; supported modifiers are ctrl, cmd, alt and shift.
      incrementKey: 'shift+Enter',
      decrementKey: 'shift+Backspace',
    },
  },
  initialState: {
    Theme: {CurrentTheme: 'dark'},
    PlusMinus: {
      PlusMinusNudges: [
        // github_stars overrides the global keys with its own combinations
        {
          Name: 'github-stars-nudge-100',
          Scope: {
            ColumnIds: ['github_stars'],
          },
          IncrementKey: 'ctrl+ArrowUp', // instead of the global 'shift+Enter'
          DecrementKey: 'ctrl+ArrowDown', // instead of the global 'shift+Backspace'
          NudgeValue: 100,
        },
        // github_watchers has no keys of its own, so it uses the global combinations
        {
          Name: 'github-watchers-nudge-200',
          Scope: {
            ColumnIds: ['github_watchers'],
          },
          NudgeValue: 200,
        },
      ],
    },
    Layout: {
      CurrentLayout: 'Standard Layout',
      Layouts: [
        {
          TableColumns: [
            'name',
            'language',
            'github_stars',
            'license',
            'github_watchers',
            'has_projects',
            'has_pages',
            'created_at',
            'has_wiki',
            'updated_at',
            'pushed_at',
            'week_issue_change',
          ],
          Name: 'Standard Layout',
          AutoSizeColumns: true,
        },
      ],
    },
    FlashingCell: {
      FlashingCellDefinitions: [
        {
          Name: 'flashingCell-github',
          Scope: {
            ColumnIds: ['github_stars', 'github_watchers'],
          },
          Rule: 'ANY_CHANGE()',
        },
      ],
    },
  },
};
```

## Creating Plus Minus Nudges

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

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

- _create_ (via the Plus / Minus Wizard)
- _edit_ (via the Plus / Minus Wizard)
- _delete_
- _suspend_
- _share_ (if Team Sharing is running)

### Using the Plus / Minus Wizard

The Plus / Minus Wizard guides you through name, scope, nudge value, an optional rule, and optional custom keys:

Provide a unique and identifiable name for the Nudge Rule.

Either choose which numeric columns can use the Nudge Rule.

Or set the `Number` DataType so that **all** numeric columns can use the Nudge Rule.

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

Set the numeric value for the Nudge Rule.

This is the amount by which the cell will increment or decrement in response to the key / press.

Select this option if the Nudge Rule should be applied whenever the columns in the Scope have the `+` or `-` keys pressed.

This is the default value.

Write an Expression which needs to be met before the Nudge Value can be applied.

This is a Boolean Expression which will be evaluated by AdapTableQL each time the `+` or `-` keys are pressed in scoped cells.

Only if the Expression returns `true` will the Nudge Rule value be applied.

By default Plus Minus Nudges are triggered when the user clicks "+" or "-" in the keyboard.

However its possible to override this on a per-Nudge basis by specifying different keys - either a single key or a keyboard shortcut combination (e.g. `shift+Enter`).

## Defining Plus Minus Nudges

Plus / Minus Nudges can be provided at design-time through [Plus Minus Initial Adaptable State](https://www.adaptabletools.com/docs/technical-reference-editing/index.md) with the following steps:

### Providing Plus Minus Nudges in Initial State

Each nudge has a unique `Name` in `PlusMinus.PlusMinusNudges`.

Specify which numeric columns can use the Nudge Rule, or set `Number` DataType to include **all** numeric columns.

Set `NudgeValue` — the amount by which the cell increments or decrements when the trigger keys are pressed.

Optional Boolean `Rule` (AdapTableQL). The nudge applies only when the rule evaluates to `true`.

Optional `IncrementKey` / `DecrementKey` override the default `+` / `-` (or global keys from Plus Minus Options).

```ts [[1, 6, "Name"], [1, 11, "Name"], [1, 17, "Name"], [2, 7, "Scope"], [2, 12, "Scope"], [2, 18, "Scope"], [3, 8, "NudgeValue"], [3, 14, "NudgeValue"], [3, 19, "NudgeValue"], [4, 13, "Rule"], [5, 20, "IncrementKey"], [5, 21, "DecrementKey"]]
// Three Plus Minus nudges on Web Frameworks columns
const initialState: InitialState = {
  PlusMinus: {
    PlusMinusNudges: [
      {
        Name: 'stars-watchers-100',
        Scope: { ColumnIds: ['github_stars', 'github_watchers'] },
        NudgeValue: 100,
      },
      {
        Name: 'stars-typescript-500',
        Scope: { ColumnIds: ['github_stars'] },
        Rule: '[language]="TypeScript"',
        NudgeValue: 500,
      },
      {
        Name: 'stars-watchers-30-xy',
        Scope: { ColumnIds: ['github_stars', 'github_watchers'] },
        NudgeValue: 30,
        IncrementKey: 'x',
        DecrementKey: 'y',
      },
    ],
  },
};
```

## UI Entitlements

Plus / Minus Nudge Rules with `ReadOnly` Entitlement can be applied but Users cannot manage or suspend them.

### FAQ

**Can I use Plus/Minus across multiple cells simultaneously?**
Yes, AdapTable will automatically apply the correct nudge value for each cell in the selection.
