# Handling Grid Data

Canonical page: https://www.adaptabletools.com/docs/handbook-managing-grid-data

- AdapTable provides Grid API methods which manage AG Grid data at runtime, including to:
  - Load Grid Data (including delayed / replacement loads)
  - Add, update or delete rows (individually or in a single transaction)
  - Set one or more Grid Cell values

The [Grid API](https://www.adaptabletools.com/docs/technical-reference-managing-grid-data/index.md#grid-api) section of [Adaptable API](https://www.adaptabletools.com/docs/technical-reference-adaptable-api/index.md) contains many functions to access AG Grid at run-time.

These include a series of data-management functions:

- [Loading (including delayed) Grid Data](https://www.adaptabletools.com/docs/handbook-managing-grid-data-loading/index.md)
- [Managing Row Data](https://www.adaptabletools.com/docs/handbook-managing-grid-data-rows-transaction/index.md)
- [Adding Row Data](https://www.adaptabletools.com/docs/handbook-managing-grid-data-rows-add/index.md)
- [Updating Row Data](https://www.adaptabletools.com/docs/handbook-managing-grid-data-rows-update/index.md)
- [Setting Individual Cell Values](https://www.adaptabletools.com/docs/handbook-managing-grid-data-cells/index.md)
- [Deleting Row Data](https://www.adaptabletools.com/docs/handbook-managing-grid-data-rows-delete/index.md)

- We strongly recommend **using these functions to update AG Grid**, rather than the AG Grid API directly
- Each function ultimately calls an AG Grid function, and around it AdapTable:
  - finds the rows by their [Primary Key](https://www.adaptabletools.com/docs/getting-started-primary-key/index.md)
  - reports every cell that changed, including in rows that are not rendered (AG Grid on its own reports changes only for rendered rows)
  - re-filters the Grid, refreshes columns that depend on every row and checks the selection once per call, rather than once per changed row

Most of these Grid API functions will do 2 things (that vary based on the use case):

- update AG Grid using the relevant AG Grid api function
- trigger an AdapTable Event - either [Row Changed](https://www.adaptabletools.com/docs/technical-reference-managing-grid-data/index.md) (with a Trigger) or [Cell Changed](https://www.adaptabletools.com/docs/technical-reference-editing/index.md)

The full details are as follows:

| Use Case            | AdapTable Function               | AG Grid Function Invoked            | AdapTable Event | Trigger                     |
| ------------------- | -------------------------------- | ----------------------------------- | --------------- | --------------------------- |
| Loading Grid Data   | `loadGridData`                   | `setRowData`                        | Row Changed     | `Load`                      |
| Managing Rows       | `manageGridData`                 | `applyTransaction`                  | Row Changed     | `Add` / `Update` / `Delete` |
| Adding Rows         | `addGridData`                    | `applyTransaction` `add`            | Row Changed     | `Add`                       |
| Updating Rows       | `updateGridData`                 | `applyTransaction` `update`         | Row Changed     | `Update`                    |
| Add or Update Rows  | `addOrUpdateGridData`            | `applyTransaction` `add` / `update` | Row Changed     | `Add` / `Update`            |
| Deleting Rows       | `deleteGridData`                 | `applyTransaction` `remove`         | Row Changed     | `Delete`                    |
| Setting Cell Values | `setCellValue` / `setCellValues` | `rowNode.setDataValue`              | Cell Changed    |                             |

The functions that invoke `applyTransaction` might call `applyTransactionAsync` based on the config they are given
