logo

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

Information:
Options passed into addDataExport.
const table = createTable(data, {
  export: addDataExport({ ... }),
});
const table = createTable(data, {
  export: addDataExport({ ... }),
});

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

Export format. Default 'object'.

childrenKey?: string

Property key for sub-rows for 'object'/'json' formats. Default 'children'.

Column Options

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

exclude?: boolean

Exclude a column from the export.

Prop Set

Information:
Extensions to the view model. Subscribe to .props().
{#each $headerRows as headerRow (headerRow.id)}
  <Subscribe rowProps={headerRow.props()} let:rowProps>
    {rowProps.export}
    {#each headerRow.cells as cell (cell.id)}
      <Subscribe props={cell.props()} let:props>
        {props.export}
      </Subscribe>
    {/each}
  </Subscribe>
{/each}
{#each $headerRows as headerRow (headerRow.id)}
  <Subscribe rowProps={headerRow.props()} let:rowProps>
    {rowProps.export}
    {#each headerRow.cells as cell (cell.id)}
      <Subscribe props={cell.props()} let:props>
        {props.export}
      </Subscribe>
    {/each}
  </Subscribe>
{/each}

Plugin State

Information:
State provided by addDataExport.
const { headerRows, rows, pluginStates } = table.createViewModel(columns);
const { ... } = pluginStates.export;
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'

Subscribe to exportedData or use get to compute once.