# Highlighting and Jumping

Canonical page: https://www.adaptabletools.com/docs/handbook-highlighting-jumping

- The [`Grid API`](https://www.adaptabletools.com/docs/reference/gridapi.md) provides highlight and jump helper functions for temporary, code-driven focus and styling:
  - **Highlights** use an [Adaptable Style](https://www.adaptabletools.com/docs/ui-tutorial-providing-adaptable-style/index.md) object (optional timeout)
  - **Jump** moves scroll/focus to a row, column or cell (often used together with highlights)

The [`Grid API`](https://www.adaptabletools.com/docs/reference/gridapi.md) includes helpers for two related, grid-level actions:

- **Highlighting** cells, rows and columns
- **Jumping** to rows, columns and cells

- This page shows highlighting & jumping via Grid API directly; AdapTable modules with similar behaviour include:
  - [Alert Behaviours](https://www.adaptabletools.com/docs/handbook-alerting-behaviours/index.md) — when an alert fires you can configure Highlight Cell (or Row) and Jump to Cell (or Row)
  - [Flashing Cells](https://www.adaptabletools.com/docs/handbook-flashing-cell/index.md) — flashes when a Change or Observable rule is true
  - [Format Column](https://www.adaptabletools.com/docs/handbook-column-formatting/index.md) — persistent column styling or conditional formatting

## Highlighting

There are a number of Grid API functions which facilitate cell, row and column highlighting:

- `highlightCell`
- `unHighlightCell`
- `unHighlightAllCells`
- `highlightColumn`
- `unHighlightColumn`
- `unHighlightAllColumns`
- `highlightRow`
- `highlightRows`
- `unHighlightRow`
- `unHighlightRows`
- `unHighlightAllRows`

Grid API highlighting is impermanent and caller-controlled (you clear it or rely on a timeout*

**Example: Highlighting Cells and Rows**

Using Grid API to highlight cells and rows in AdapTable

- This demo provides examples of highlighting and unhighlighting using the [`Grid API`](https://www.adaptabletools.com/docs/reference/gridapi.md) (using Custom Toolbar Buttons):
  - First button calls `highlightCell` to highlight the `Name` cell for _ember.js_ with a white fore colour and purple back colour (timeout 5 seconds)
  - Second button calls `highlightRow` to highlight the whole row for _Solid_ with a gray fore colour and brown back colour
  - Third button calls `unHighlightRow` for the _Solid_ row, which clears the highlight
  - Fourth button calls `highlightColumn` for the Github Stars column (timeout 3 seconds)

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 {
  AdaptableButton,
  AdaptableOptions,
  CellHighlightInfo,
  CustomToolbarButtonContext,
  RowHighlightInfo,
} from '@adaptabletools/adaptable';
import {WebFramework} from './rowData';

export const adaptableOptions: AdaptableOptions<WebFramework> = {
  primaryKey: 'id',
  adaptableId: 'Highlighting API',
  dashboardOptions: {
    customToolbars: [
      {
        name: 'ButtonToolbar',
        title: 'Buttons',
        toolbarButtons: [
          {
            label: 'Highlight "ember.js" (5 secs)',
            onClick: (
              button: AdaptableButton<CustomToolbarButtonContext>,
              context: CustomToolbarButtonContext
            ) => {
              // Highlight a cell for 5 seconds
              const cellHighlightInfo: CellHighlightInfo = {
                columnId: 'name',
                primaryKeyValue: 1801829,
                timeout: 5000,
                highlightStyle: {
                  BackColor: 'var(--ab-color-palette-28)',
                  ForeColor: 'var(--ab-color-palette-14)',
                },
              };
              context.adaptableApi.gridApi.highlightCell(cellHighlightInfo);
            },
            buttonStyle: {
              tone: 'info',
              variant: 'text',
            },
          },
          {
            label: 'Highlight "solid" Row',
            onClick: (
              button: AdaptableButton<CustomToolbarButtonContext>,
              context: CustomToolbarButtonContext
            ) => {
              const rowHighlightInfo: RowHighlightInfo = {
                primaryKeyValue: 130884470,
                highlightStyle: {
                  BackColor: 'var(--ab-color-palette-17)',
                  ForeColor: 'var(--ab-color-palette-16)',
                },
              };
              context.adaptableApi.gridApi.highlightRow(rowHighlightInfo);
            },
            buttonStyle: {
              tone: 'success',
              variant: 'text',
            },
          },
          {
            label: 'Unighlight "solid" Row',
            onClick: (
              button: AdaptableButton<CustomToolbarButtonContext>,
              context: CustomToolbarButtonContext
            ) => {
              context.adaptableApi.gridApi.unHighlightRow(130884470);
            },
            buttonStyle: {
              tone: 'warning',
              variant: 'text',
            },
          },
          {
            label: 'Highlight Github Watchers Column (3 secs)',
            onClick: (
              button: AdaptableButton<CustomToolbarButtonContext>,
              context: CustomToolbarButtonContext
            ) => {
              context.adaptableApi.gridApi.highlightColumn({
                columnId: 'github_watchers',
                highlightStyle: {
                  BackColor: 'var(--ab-color-palette-17)',
                  ForeColor: 'var(--ab-color-palette-16)',
                },
                timeout: 3000,
              });
            },
            buttonStyle: {
              tone: 'error',
              variant: 'text',
            },
          },
        ],
      },
    ],
  },
  initialState: {
    Dashboard: {
      Tabs: [
        {
          Name: 'Demo',
          Toolbars: ['ButtonToolbar'],
        },
      ],
    },
    Theme: {CurrentTheme: 'dark'},
    Layout: {
      CurrentLayout: 'Standard Layout',
      Layouts: [
        {
          TableColumns: [
            'name',
            'language',
            'github_stars',
            'license',
            'created_at',
            'has_wiki',
            'github_watchers',
            'updated_at',
            'pushed_at',
            'description',
            'open_issues_count',
            'closed_issues_count',
            'open_pr_count',
            'closed_pr_count',
            'has_projects',
            'has_pages',
            'week_issue_change',
          ],
          Name: 'Standard Layout',
          AutoSizeColumns: true,
        },
      ],
    },
  },
};
```

### Style

Each highlight function receives a commonly used [Adaptable Style](https://www.adaptabletools.com/docs/ui-tutorial-providing-adaptable-style/index.md) object which contains numerous properties, allowing for full control over how the highlight looks.

### Timeout

The highlight functions can be provided with a timeout specifying how long the cell or row will remain highlighted.

### Highlight Info Objects and Styles

The highlight functions receive a [`CellHighlightInfo`](https://www.adaptabletools.com/docs/reference/cellhighlightinfo.md) or a [`RowHighlightInfo`](https://www.adaptabletools.com/docs/reference/rowhighlightinfo.md) object as needed.

Both provide details of the Cell / Row to be highlighted and the [Adaptable Style](https://www.adaptabletools.com/docs/ui-tutorial-providing-adaptable-style/index.md) to use

The `CellHighlightInfo` object is defined as follows:

| Property | Type | Description |
| --- | --- | --- |
| [columnId](https://www.adaptabletools.com/docs/reference/cellhighlightinfo.md#columnid) | `string` | Id of Column containing Cell |
| [highlightStyle](https://www.adaptabletools.com/docs/reference/cellhighlightinfo.md#highlightstyle) | [`AdaptableStyle`](https://www.adaptabletools.com/docs/reference/adaptablestyle.md) | Adaptable Style to use in the Cell Highlight |
| [primaryKeyValue](https://www.adaptabletools.com/docs/reference/cellhighlightinfo.md#primarykeyvalue) | `any` | Primary Key Value of row containing Cell |
| [timeout](https://www.adaptabletools.com/docs/reference/cellhighlightinfo.md#timeout) | `number` | Milliseconds before the highlight is removed. Omit it and the highlight stays until it is cleared. |

The `RowHighlightInfo` is defined as follows:

| Property | Type | Description |
| --- | --- | --- |
| [highlightStyle](https://www.adaptabletools.com/docs/reference/rowhighlightinfo.md#highlightstyle) | [`AdaptableStyle`](https://www.adaptabletools.com/docs/reference/adaptablestyle.md) | Highlight style |
| [primaryKeyValue](https://www.adaptabletools.com/docs/reference/rowhighlightinfo.md#primarykeyvalue) | `any` | Primary key value for the row to be highlighted |
| [timeout](https://www.adaptabletools.com/docs/reference/rowhighlightinfo.md#timeout) | `number` | Milliseconds before the highlight is removed. Omit it and the highlight stays until it is cleared. |

Both objects contain a `highlightStyle` property of type [`AdaptableStyle`](https://www.adaptabletools.com/docs/reference/adaptablestyle.md) which has these properties:

| Property | Type | Description |
| --- | --- | --- |
| [ClassName](https://www.adaptabletools.com/docs/reference/adaptablestyle.md#classname) | `string` | CSS class added to the cell. Colour, font and border properties on this object are still applied. |

---

## Jumping

The Grid API section of AdapTable API contains 3 functions that enable moving the focus in the Grid to specific cells, rows or columns:

- `jumpToRow`
- `jumpToColumn`
- `jumpToCell`

**Example: Jumping to Cells and Rows**

Using Grid API to move focus to given Cells, Rows & Columns

- This demo provides examples of "jumping" using the [`Grid API`](https://www.adaptabletools.com/docs/reference/gridapi.md)
- We provide 3 Custom Toolbar Buttons which each call a jump-related function:
  - First button calls `jumpToCell` function to jump to `Created At` in the _Quasar_ row (the last row in the grid)
  - Second button calls `jumpToRow` function to jump to _Angular_ row (2nd from top)
  - Third button calls `jumpToColumn` function to jump to the `Issue Change` column (at the far end of the grid)
- Additionally we provide a [Custom Context Menu Item](https://www.adaptabletools.com/docs/ui-context-menu-custom-items/index.md) that displays all Columns in the Grid, and AdapTable will jump to the Column selected

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 {
  AdaptableButton,
  AdaptableColumn,
  AdaptableOptions,
  CellHighlightInfo,
  CustomContextMenuContext,
  CustomToolbarButtonContext,
  RowHighlightInfo,
  UserContextMenuItem,
} from '@adaptabletools/adaptable';
import {WebFramework} from './rowData';

export const adaptableOptions: AdaptableOptions<WebFramework> = {
  primaryKey: 'id',
  adaptableId: 'Jumping Functions',
  contextMenuOptions: {
    customContextMenu: (context: CustomContextMenuContext) => {
      const {
        defaultAgGridMenuStructure,
        defaultAdaptableMenuStructure,
        adaptableApi,
      } = context;

      const columnNameMenuItems: UserContextMenuItem[] = adaptableApi.columnApi
        .getVisibleColumns()
        .map((c: AdaptableColumn) => {
          return {
            menuType: 'User',
            label: c.friendlyName,
            onClick: () => {
              adaptableApi.gridApi.jumpToColumn(c.columnId);
            },
          };
        });

      const jumpToColumnMenuItem: UserContextMenuItem = {
        menuType: 'User',
        label: 'Jump To',
        icon: {
          name: 'greater-than',
        },
        subMenuItems: columnNameMenuItems,
      };

      return [
        jumpToColumnMenuItem,
        ...defaultAgGridMenuStructure,
        '-',
        ...defaultAdaptableMenuStructure,
      ];
    },
  },
  dashboardOptions: {
    customToolbars: [
      {
        name: 'ButtonToolbar',
        title: 'Buttons',
        toolbarButtons: [
          {
            label: 'Jump to "Qasar" / Created At',
            onClick: (
              button: AdaptableButton<CustomToolbarButtonContext>,
              context: CustomToolbarButtonContext
            ) => {
              context.adaptableApi.gridApi.jumpToCell(43695474, 'created_at');
            },
            buttonStyle: {
              tone: 'info',
              variant: 'text',
            },
          },
          {
            label: 'Jump to "Angular" Row',
            onClick: (
              button: AdaptableButton<CustomToolbarButtonContext>,
              context: CustomToolbarButtonContext
            ) => {
              context.adaptableApi.gridApi.jumpToRow(24195339);
            },
            buttonStyle: {
              tone: 'success',
              variant: 'text',
            },
          },
          {
            label: 'Jump to "Issue Change" Column',
            onClick: (
              button: AdaptableButton<CustomToolbarButtonContext>,
              context: CustomToolbarButtonContext
            ) => {
              context.adaptableApi.gridApi.jumpToColumn('week_issue_change');
            },
            buttonStyle: {
              tone: 'warning',
              variant: 'text',
            },
          },
        ],
      },
    ],
  },
  initialState: {
    Dashboard: {
      Tabs: [
        {
          Name: 'Demo',
          Toolbars: ['ButtonToolbar'],
        },
      ],
    },
    Theme: {CurrentTheme: 'dark'},
    Layout: {
      CurrentLayout: 'Standard Layout',
      Layouts: [
        {
          TableColumns: [
            'name',
            'language',
            'github_stars',
            'license',
            'created_at',
            'has_wiki',
            'github_watchers',
            'updated_at',
            'pushed_at',
            'description',
            'open_issues_count',
            'closed_issues_count',
            'open_pr_count',
            'closed_pr_count',
            'has_projects',
            'has_pages',
            'week_issue_change',
          ],
          Name: 'Standard Layout',
          AutoSizeColumns: true,
        },
      ],
    },
  },
};
```
