Setting AG Grid Cell Data Types

View as Markdown

Summary

  • Developers should provide the cellDataType property as part of each AG Grid Column definition
  • AdapTable will then set the data types of the columns, ensuring filters and menus are correctly configured

AdapTable needs to know the correct data type of each Column in AG Grid.

Note

This will ensure that appropriate Filter Types, Column Menus etc. are configured correctly for the Column

AdapTable does this by leveraging the cellDataType property that is part of each AG Grid ColDef object.

If this is not provided, AdapTable will attempt to work out the DataType of the column, by analysing the data in the first row of the Grid.

Caution

Not providing Column Data Types can cause issues, particularly if the data in the first row is missing or ambiguous

AG Grid Cell Data Types

When setting up Column Definitions, developers should ensure to set the correct cellDataType property.

For the vast majority of Columns, the default values provided by AG grid will suffice:

Column Data TypeAG Grid cellDataType value
Stringtext
Numericnumber
Datedate
Date (as string)dateString
Booleanboolean
Objectobject
const gridOptions: GridOptions = {
  columnDefs: [
    {
      headerName: 'Make',
      field: 'make',
      cellDataType: 'text',
    },
    {
      headerName: 'Released',
      field: 'released',
      cellDataType: 'date',
    },
    {
      headerName: 'Updated',
      field: 'updated',
      cellDataType: 'dateString',
    },
    {
      headerName: 'Bid',
      field: 'bid',
      cellDataType: 'number',
      type: 'pricing', // `type` is for Column Types, not data types
    },
    {
      headerName: 'Automatic',
      field: 'automaticTransmission',
      cellDataType: 'boolean',
    },
  ],
};
AG Grid Cell Data Types
Fork
  • This demo shows how AdapTable leverages AG Grid Cell Data Types using a (nonsensical) data set with these columns:
    • Make and Model are text
    • Price and Rating are numbers
    • Available is a boolean
    • Made is a date and Produced is a dateString - but both become AdapTable Dates (and therefore they share the same Format Column)
Loading demo…

Custom Cell Data Types

AG Grid also lets you register custom types via dataTypeDefinitions on GridOptions.

AdapTable still uses the column's AdapTable data type for filters and menus. Calculated Columns and FreeText Columns can optionally set CellDataType so AG Grid renders the cell with a registered custom type (for example currency or percentage) while the AdapTable DataType stays number.

Array Types

There are a few use cases (all regarding array data) where the AG Grid types are insufficient.

In this case AdapTable provides a number of different array-based cell data types.

Find Out More

See creating Array Columns for full details and accompanying demos