Skip to content

ExportPlugin

Export Plugin for tbw-grid

Lets users download grid data as CSV, Excel (XML), or JSON with a single click or API call. Great for reporting, data backup, or letting users work with data in Excel. Integrates with SelectionPlugin to export only selected rows.

import { ExportPlugin } from '@toolbox-web/grid/plugins/export';
FormatMethodDescription
CSVexportToCSV()Comma-separated values
ExcelexportToExcel()Excel XML format (.xlsx)
JSONexportToJSON()JSON array of objects
OptionTypeDescription
fileName?stringDefault file name for exports (default: ‘export’)
includeHeaders?booleanInclude column headers in export (default: true)
onlyVisible?booleanExport only visible columns (default: true)
onlySelected?booleanExport only selected rows (default: false)
import { queryGrid } from '@toolbox-web/grid';
import { ExportPlugin } from '@toolbox-web/grid/plugins/export';
const grid = queryGrid('tbw-grid');
grid.gridConfig = {
columns: [
{ field: 'name', header: 'Name' },
{ field: 'email', header: 'Email' },
],
plugins: [new ExportPlugin({ fileName: 'employees', includeHeaders: true })],
};
// Trigger export via button
document.getElementById('export-btn').addEventListener('click', () => {
grid.getPluginByName('export').exportToCSV();
});
import { SelectionPlugin } from '@toolbox-web/grid/plugins/selection';
grid.gridConfig = {
plugins: [
new SelectionPlugin({ mode: 'row' }),
new ExportPlugin({ onlySelected: true }),
],
};
  • ExportConfig for all configuration options
  • ExportParams for method parameters
  • SelectionPlugin for exporting selected rows

Extends BaseGridPlugin

Inherited methods like attach(), detach(), afterRender(), etc. are documented in the base class.

Returns the row data that would be included in an export, without producing a file. Honours mode, onlyVisible, onlySelected, columns, rowIndices, processCell, and (for mode: 'formatted') column.format.

Each returned object is keyed by column.field in column order.

export(params: Partial<ExportParams>): Record<string, unknown>[]
NameTypeDescription
paramsPartial<ExportParams>
// Underlying typed values (Date stays Date, number stays number)
const raw = exporter.export();
// What the user sees in each cell
const display = exporter.export({ mode: 'formatted' });

Returns the columns (in order) that an export with these params would include. Useful when handing rows to a third-party serializer that needs header labels, widths, or types alongside the data.

getResolvedColumns(params: Partial<ExportParams>): ColumnConfig<any>[]
NameTypeDescription
paramsPartial<ExportParams>

Format an array of row objects as a CSV string. Column order, headers, and which fields to emit are taken from the plugin’s resolved columns (respecting onlyVisible and params.columns).

This is a pure formatter — it does not re-resolve values from the grid. Pass data produced by ExportPlugin.export (or any compatible row objects keyed by column.field).

params.processCell is honoured: it runs once per cell on the values in data. mode is not accepted here — apply it upstream via export({ mode: 'formatted' }).

formatCsv(data: Record<string, unknown>[], params: FormatCsvParams, options: CsvOptions): string
NameTypeDescription
dataRecord<string, unknown>[]
paramsFormatCsvParams
optionsCsvOptions
const csv = exporter.formatCsv(exporter.export());
await navigator.clipboard.writeText(csv);

Format an array of row objects as an Excel XML Spreadsheet 2003 string. See formatCsv for the data-shape contract — this method is also a pure formatter and params.processCell is honoured the same way.

formatExcel(data: Record<string, unknown>[], params: FormatExcelParams): string
NameTypeDescription
dataRecord<string, unknown>[]
paramsFormatExcelParams

Export data to CSV format.

exportCsv(params: Partial<ExportParams>): void
NameTypeDescription
paramsPartial<ExportParams>Optional export parameters

Export data to Excel format (XML Spreadsheet).

exportExcel(params: Partial<ExportParams>): void
NameTypeDescription
paramsPartial<ExportParams>Optional export parameters

Export data to JSON format.

exportJson(params: Partial<ExportParams>): void
NameTypeDescription
paramsPartial<ExportParams>Optional export parameters

Check if an export is currently in progress.

isExporting(): boolean

boolean - Whether export is in progress


Get information about the last export.

getLastExport(): object | null

object | null - Export info or null if no export has occurred


AI assistants: For complete API documentation, implementation guides, and code examples for this library, see https://raw.githubusercontent.com/OysteinAmundsen/toolbox/main/llms-full.txt