1. Plugins
  2. addDataExport

Plugins

addDataExport

addDataExport allows for reading the data source as it is currently transformed by the table.

This is useful if you need to export data from the table with all plugin transformations applied.

WARNING

Display columns do not contain any data by default and will show up as null in the data export.

If you need to add data to a display column, use the data property when defining the display column.

Options

Options passed into addDataExport.

const table = createTable(data, {
  export: addDataExport({ ... }),
});

format?: 'object' | 'json' | 'csv'

Sets the exported data format.

Defaults to 'object'.

childrenKey?: string

The property key to store sub-rows under.

This only applies if format is 'object' or 'json'.

Defaults to 'children'.

Column Options

Options passed into column definitions.

const columns = table.createColumns([
  table.column({
    header: 'Name',
    accessor: 'name',
    plugins: {
      export: { ... },
    },
  }),
]);

exclude?: boolean

Excludes the column from the data export.

Defaults to false.

Prop Set

Extensions to the view model.

Subscribe to .props() on the respective table components.

{#each $headerRows as headerRow (headerRow.id)}
  <Subscribe rowProps={headerRow.props()} let:rowProps>
    {rowProps.export} <!-- HeaderRow props -->
    {#each headerRow.cells as cell (cell.id)}
      <Subscribe props={cell.props()} let:props>
        {props.export} <!-- HeaderCell props -->
      </Subscribe>
    {/each}
  </Subscribe>
{/each}

Nothing here so far.

Plugin State

State provided by addDataExport.

const { headerRows, rows, pluginStates } = table.createViewModel(columns);
const { ... } = pluginStates.export;

exportedData: Readable<DataExport>

The exported data. DataExport is:

  • Record<string, unknown>[] if format is 'object'
  • string if format is 'json'
  • string if format is 'csv'

Either subscribe to exportedData or use get to compute the exported data once.