# Creating Array Columns

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

- Array Columns contain multiple values in each Cell
- AdapTable supports these and enables rendering in Badge Styles or Sparkline Columns
- Calculated Columns which contain arrays can also be created
- Filtering is available in Array Columns using the In Filter

AG Grid provides [Cell Data Types](https://www.adaptabletools.com/docs/dev-guide-aggrid-cell-data-types/index.md) which AdapTable leverages to know the data type of a Column.

This allows AdapTable to create the correct Filters and Menus

For the majority of Columns, these cell data types are all that is needed.

However, there are a few use cases - all regarding array data - where the AG Grid types are insufficient.

In these scenarios, one of these array values provided by AdapTable should be used instead:

- `textArray` 
- `numberArray` 
- `tupleArray` 
- `objectArray` 

## Sparkline Columns

If defining a Column that will use a [Sparkline Column Style](https://www.adaptabletools.com/docs/handbook-styled-column-sparkline/index.md) then a numeric array is required.

AdapTable provides 3 types of numeric arrays:

| Type of Data             | Value for `cellDataType` property | Example                                              |
| ------------------------ | --------------------------------- | ---------------------------------------------------- |
| Numeric Array            | `numberArray`                     | `[27, 5, 13, 25]`                                    |
| Array of Numeric Tuples  | `tupleArray`                      | `[ [14, 22], [5, 13], [19, 30] ]`                    |
| Array of Numeric Objects | `objectArray`                     | `[ \{x: 14, y: 22\}, \{x: 5, y: 13\}, \{x: 19, y: 30\} ]` |

```tsx {6,11}
const gridOptions: GridOptions = {
  columnDefs: [
    {
      headerName: 'History',
      field: 'history',
      cellDataType: 'numberArray',
    },
    {
      headerName: 'Prices',
      field: 'prices',
      cellDataType: 'tupleArray',
    },
  ],
};
```

## Badge Styles

A common use case when creating a [Badge Style](https://www.adaptabletools.com/docs/handbook-styled-column-badge/index.md#arrays) is to show a distinct badge for each separate item in a cell.

Again, the way to achieve this is to use an AdapTable-provided value for the cellDataType.

| Type of Data | Value for `cellDataType` property | Example                                 |
| ------------ | --------------------------------- | --------------------------------------- |
| String Array | `textArray` (or `numberArray`)    | ['US', 'GBP', 'France'] (or [19,11,27]) |

It is also possible to use the `numberArray` cell data type in Array Badge Styles

```tsx {6}
const gridOptions: GridOptions = {
  columnDefs: [
    {
      headerName: 'Institutions',
      field: 'institutions',
      cellDataType: 'textArray',
    },
  ],
};
```

## Calculated Columns

It is possible to create [Calculated Columns](https://www.adaptabletools.com/docs/handbook-calculated-column/index.md) which will display Array data.

Typically the Calculated Column's Expresssion will include the `TO_ARRAY` [Expression Function](https://www.adaptabletools.com/docs/adaptable-ql-expression-functions/index.md) to create the array.

- When defining the Calculated Column, an appropriate array cell data type should be used (e.g. numeric or string)
- If using the Calculated Column UI Wizard, AdapTable works out the appropriate cell data type from the Expression

You can create a Sparkline Column to render the Calculated Column's array if required

## Filtering

AdapTable fully supports Column Filtering in Array based columns.

The [In Filter](https://www.adaptabletools.com/docs/handbook-column-filter-in-filter/index.md) is used as the default Filter type, and any row which contains a selected value is displayed.

**Example: Array Cell Data Type**

Using Array Columns

- This demo contains 2 array-based Columns:
  - `Institutions` column (`textArray`) - we created 7 Badges each with a Rule (per institution), and a (Green) Badge for institutions which do not meet any Rule
  - `Ratings` column (`numberArray`) - shows a Sparkline Column - note this column is a Calculated Column where the array is the output of a `TO_ARRAY` [Expression Function](https://www.adaptabletools.com/docs/adaptable-ql-expression-functions/index.md)

- Filter the `Institutions` Column so that just rows containing Princeton or Columbia are visible

Demo project (Vanilla); the files without a marker are shown below:

```text
src/
  adaptableOptions.ts
  agGridModules.ts     [template, with charts]
  columnDefs.ts
  gridOptions.ts       [template]
  index.ts             [template]
  onAdaptableReady.ts  [template]
  rowData.ts
  styles.css           [template]
index.html             [template]
package.json           [template] + ag-charts-enterprise
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';

export const adaptableOptions: AdaptableOptions = {
  primaryKey: 'EmployeeId',
  adaptableId: 'Array Cell Data Type',
  initialState: {
    Dashboard: {
      ModuleButtons: ['StyledColumn', 'CalculatedColumn'],
    },
    Theme: {CurrentTheme: 'dark'},
    Layout: {
      CurrentLayout: 'Basic Layout',
      Layouts: [
        {
          Name: 'Basic Layout',
          TableColumns: [
            'Name',
            'Year',
            'Country',
            'CountryCode',
            'Institutions',
            'Email',
            'Ratings',
            'Rating2025',
            'Rating2024',
            'Rating2023',
            'Rating2022',
            'Rating2021',
          ],
          ColumnSizing: {
            Name: {Width: 130},
            Year: {Width: 80},
            Country: {Width: 150},
            CountryCode: {Width: 120},
            Institutions: {Width: 300},
            Email: {Width: 150},
            Ratings: {Width: 300},
            Rating2025: {Width: 100},
            Rating2024: {Width: 100},
            Rating2023: {Width: 100},
            Rating2022: {Width: 100},
            Rating2021: {Width: 100},
          },
        },
      ],
    },
    CalculatedColumn: {
      CalculatedColumns: [
        {
          ColumnId: 'Ratings',
          FriendlyName: 'Ratings',
          Expression: 'TO_ARRAY([Rating2025], [Rating2024], [Rating2023], [Rating2022], [Rating2021])',
          CalculatedColumnSettings: {
            Resizable: true,
            DataType: 'numberArray',
          },
        },
      ],
    },
    StyledColumn: {
      StyledColumns: [
        {
          Name: 'Institutions Badge',
          ColumnId: 'Institutions',
          BadgeStyle: {
            Badges: [
              {
                PillStyle: {
                  BackColor: 'LightGreen',
                  ForeColor: 'var(--ab-color-palette-13)',
                },
                Rule: '[Institutions] = "Columbia"',
              },
              {
                PillStyle: {
                  BackColor: 'var(--ab-color-palette-28)',
                  ForeColor: 'var(--ab-color-palette-14)',
                },
                Rule: '[Institutions] = "Princeton"',
              },
              {
                PillStyle: {
                  BackColor: 'var(--ab-color-palette-17)',
                  ForeColor: 'var(--ab-color-palette-14)',
                },
                Rule: '[Institutions] = "Max Planck"',
              },
              {
                PillStyle: {
                  BackColor: 'var(--ab-color-palette-32)',
                  ForeColor: 'var(--ab-color-palette-13)',
                },
                Rule: '[Institutions] = "Geneva"',
              },
              {
                PillStyle: {
                  BackColor: 'LightBlue',
                  ForeColor: 'var(--ab-color-palette-13)',
                },
                Rule: '[Institutions] = "University of Cambridge"',
              },
              {
                PillStyle: {
                  BackColor: 'var(--ab-color-palette-23)',
                  ForeColor: 'var(--ab-color-palette-14)',
                },
                Rule: '[Institutions] = "Oxford University"',
              },
              {
                PillStyle: {
                  BackColor: 'Pink',
                  ForeColor: 'var(--ab-color-palette-13)',
                },
                Rule: '[Institutions] = "Hamburg"',
              },
              {
                PillStyle: {
                  BackColor: 'var(--ab-color-palette-18)',
                  ForeColor: 'var(--ab-color-palette-14)',
                },
              },
            ],
          },
        },
        {
          Name: 'Ratings Sparkline',
          ColumnId: 'Ratings',
          SparklineStyle: {
            options: {
              type: 'bar',
              direction: 'horizontal',
              fill: '#5470c6',
              stroke: '#91cc75',
            },
          },
        },
      ],
    },
  },
};
```
**`src/columnDefs.ts`**

```ts
import {ColDef} from 'ag-grid-enterprise';

export const columnDefs: ColDef[] = [
  {
    headerName: 'Id',
    field: 'EmployeeId',
    editable: false,
    sortable: true,
    cellDataType: 'text',
  },
  {
    headerName: 'Name',
    field: 'Name',
    filter: true,
    editable: false,
    sortable: true,
    cellDataType: 'text',
  },
  {
    headerName: 'Year',
    field: 'Year',
    filter: true,
    editable: false,
    sortable: true,
    cellDataType: 'number',
  },
  {
    headerName: 'Institutions',
    field: 'Institutions',
    filter: true,
    editable: false,
    sortable: true,
    cellDataType: 'textArray',
  },
  {
    headerName: 'Country',
    field: 'Country',
    filter: true,
    editable: false,
    sortable: true,
    cellDataType: 'text',
  },
  {
    headerName: 'CountryCode',
    field: 'CountryCode',
    filter: true,
    editable: false,
    sortable: true,
    cellDataType: 'text',
  },

  {
    headerName: 'Email',
    field: 'Email',
    filter: true,
    editable: false,
    sortable: true,
    cellDataType: 'text',
  },
  {
    headerName: '2025 Rating',
    field: 'Rating2025',
    filter: true,
    editable: true,
    sortable: true,
    cellDataType: 'number',
  },
  {
    headerName: '2024 Rating',
    field: 'Rating2024',
    filter: true,
    editable: true,
    sortable: true,
    cellDataType: 'number',
  },
  {
    headerName: '2023 Rating',
    field: 'Rating2023',
    filter: true,
    editable: true,
    sortable: true,
    cellDataType: 'number',
  },
  {
    headerName: '2022 Rating',
    field: 'Rating2022',
    filter: true,
    editable: true,
    sortable: true,
    cellDataType: 'number',
  },
  {
    headerName: '2021 Rating',
    field: 'Rating2021',
    filter: true,
    editable: true,
    sortable: true,
    cellDataType: 'number',
  },
];
```
**`src/rowData.ts`**

```ts
export const rowData = [
  {
    EmployeeId: 1,
    Name: 'Giorgio Parisi',
    Year: 2021,
    Institutions: ['Sapienza', 'Columbia'],
    Country: 'Italy',
    CountryCode: 'ITA',
    Email: 'giorgio.parisi@mail.com',
    Rating2025: 4,
    Rating2024: 7,
    Rating2023: 5,
    Rating2022: 8,
    Rating2021: 8,
  },
  {
    EmployeeId: 2,
    Name: 'Klaus Hasselman',
    Year: 2021,
    Institutions: ['Hamburg', 'Max Planck'],
    Country: 'Germany',
    CountryCode: 'DEU',
    Email: 'klaus.hasselman@yahoo.com',
    Rating2025: 5,
    Rating2024: 3,
    Rating2023: 7,
    Rating2022: 7,
    Rating2021: 4,
  },
  {
    EmployeeId: 3,
    Name: 'Syukor Manabe',
    Year: 2021,
    Institutions: ['Princeton', 'Nagoya'],
    Country: 'Japan',
    CountryCode: 'JPN',
    Email: 'syukor.manabe@outlook.com',
    Rating2025: 6,
    Rating2024: 7,
    Rating2023: 6,
    Rating2022: 8,
    Rating2021: 6,
  },
  {
    EmployeeId: 4,
    Name: 'Andrea Ghez',
    Year: 2020,
    Institutions: ['University of Cambridge'],
    Country: 'United States',
    CountryCode: 'USA',
    Email: 'andrea.ghez@mail.com',
    Rating2025: 10,
    Rating2024: 7,
    Rating2023: 8,
    Rating2022: 8,
    Rating2021: 6,
  },
  {
    EmployeeId: 5,
    Name: 'Reinhard Genzel',
    Year: 2020,
    Institutions: ['Max Planck', 'Oxford University'],
    Country: 'Germany',
    CountryCode: 'DEU',
    Email: 'reinhard.genzel@mail.com',
    Rating2025: 9,
    Rating2024: 5,
    Rating2023: 8,
    Rating2022: 7,
    Rating2021: 8,
  },
  {
    EmployeeId: 6,
    Name: 'Roger Penrose',
    Year: 2020,
    Institutions: ['Columbia', 'Princeton', 'Syracuse'],
    Country: 'United Kingdom',
    CountryCode: 'GBR',
    Email: 'roger.penrose@yahoo.com',
    Rating2025: 8,
    Rating2024: 10,
    Rating2023: 10,
    Rating2022: 8,
    Rating2021: 9,
  },
  {
    EmployeeId: 7,
    Name: 'Didier Queloz',
    Year: 2019,
    Institutions: ['University of Cambridge', 'Geneva'],
    Country: 'Switzerland',
    CountryCode: 'CHE',
    Email: 'didier.queloz@mail.com',
    Rating2025: 7,
    Rating2024: 5,
    Rating2023: 6,
    Rating2022: 8,
    Rating2021: 6,
  },
  {
    EmployeeId: 8,
    Name: 'Michel Mayor',
    Year: 2019,
    Institutions: ['Geneva', 'Columbia'],
    Country: 'Switzerland',
    CountryCode: 'CHE',
    Email: 'michel.mayor@yahoo.com',
    Rating2025: 9,
    Rating2024: 10,
    Rating2023: 9,
    Rating2022: 6,
    Rating2021: 8,
  },
  {
    EmployeeId: 9,
    Name: 'Jim Peebles',
    Year: 2019,
    Institutions: ['Oxford University', 'Princeton'],
    Country: 'United States',
    CountryCode: 'USA',
    Email: 'jim.peebles@outlook.com',
    Rating2025: 7,
    Rating2024: 9,
    Rating2023: 10,
    Rating2022: 9,
    Rating2021: 8,
  },
];
```

<RelatedBlogCard path="/blog/2026-01-26-adaptable-for-aggrid-array-columns" />
