Configuring Data Import

View as Markdown

Summary

  • AdapTable provides built-in handling for CSV and JSON files, and a default path for pasted text
  • Developers can replace or extend those with fileHandlers, customise paste parsing with textHandler, or take full control of applying imported rows with handleImportedData

DataImportOptions defines these stable properties for Data Import:

PropertyPurpose
fileHandlersCustom or replacement parsers for uploaded files (see below)
textHandlerParse pasted text into row objects (see Text Import)
validatePer-row validation before apply — see Validating Import Data
handleImportedDataApply imported data yourself instead of default grid update (see Custom Apply)

Other fields on DataImportOptions are documented in the reference only.

Custom File Handlers

AdapTable ships with 2 File Handlers for Data Import: CSV and JSON.

However developers can provide custom file handlers where required.

Note

These can either override an AdapTable-shipped file handler, or handle a different file type

This is done via the fileHandlers property in Data Import Options.

Custom File Handlers to use for Data Import
Data Import - Custom CSV File Handler
Fork
  • This example overrides the CSV file handler provided by AdapTable with a custom file handler, that parses CSV using a different (|) delimiter
  • Click to download updateframeworks-pipe.csv, then upload it in the Data Import wizard — it will be parsed by the custom file handler
  • We have added Flashing Cells to the grid (and increased duration to 3 seconds) so you can see the changes to the first 2 rows
Loading demo…

Text Import

When the user imports via Text in the wizard, AdapTable passes the pasted string to textHandler (if provided).

The function should return an array of row objects (or a Promise of that array), using the same shapes as file-based import.

Note

If you omit textHandler, AdapTable uses its built-in parsing for pasted content

textHandler

(text: string) => T[] | Promise<T[]>
Parse pasted text into rows for Data Import

Custom Apply

By default, after the wizard finishes, AdapTable applies imported rows to the grid (updates and adds) using the primary key.

Caution

  • If you provide handleImportedData, AdapTable does not run that default apply
  • You are responsible for updating the grid (for example via context.adaptableApi.gridApi)

When your handler finishes, you can return a HandleImportedDataResolution with addedRows, updatedRows, and emitDataImportedEvent: true if you want the DataImported event to fire.

If you return nothing (void), no automatic grid update and no event occurs.

Find Out More

See Data Imported event and DataImportApi for related run-time APIs.

handleImportedData

(context: HandleImportedDataContext) => Promise<void | HandleImportedDataResolution>
Handle imported data and apply it to the grid, or replace default application