Configuring Data Import
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 withtextHandler, or take full control of applying imported rows withhandleImportedData
DataImportOptions defines these stable properties for Data Import:
| Property | Purpose |
|---|---|
fileHandlers | Custom or replacement parsers for uploaded files (see below) |
textHandler | Parse pasted text into row objects (see Text Import) |
validate | Per-row validation before apply — see Validating Import Data |
handleImportedData | Apply 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.
fileHandlers
- 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
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[]>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>