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.
Installation
Section titled “Installation”import { ExportPlugin } from '@toolbox-web/grid/plugins/export';Supported Formats
Section titled “Supported Formats”| Format | Method | Description |
|---|---|---|
| CSV | exportToCSV() | Comma-separated values |
| Excel | exportToExcel() | Excel XML format (.xlsx) |
| JSON | exportToJSON() | JSON array of objects |
| Option | Type | Description |
|---|---|---|
fileName? | string | Default file name for exports (default: ‘export’) |
includeHeaders? | boolean | Include column headers in export (default: true) |
onlyVisible? | boolean | Export only visible columns (default: true) |
onlySelected? | boolean | Export only selected rows (default: false) |
Examples
Section titled “Examples”Basic Export with Button
Section titled “Basic Export with Button”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 buttondocument.getElementById('export-btn').addEventListener('click', () => { grid.getPluginByName('export').exportToCSV();});Export Selected Rows Only
Section titled “Export Selected Rows Only”import { SelectionPlugin } from '@toolbox-web/grid/plugins/selection';
grid.gridConfig = { plugins: [ new SelectionPlugin({ mode: 'row' }), new ExportPlugin({ onlySelected: true }), ],};See Also
Section titled “See Also”ExportConfigfor all configuration optionsExportParamsfor method parameters- SelectionPlugin for exporting selected rows
Extends BaseGridPlugin
Inherited methods like
attach(),detach(),afterRender(), etc. are documented in the base class.
Methods
Section titled “Methods”export()
Section titled “export()”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>[]Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
params | Partial<ExportParams> |
Example
Section titled “Example”// Underlying typed values (Date stays Date, number stays number)const raw = exporter.export();
// What the user sees in each cellconst display = exporter.export({ mode: 'formatted' });getResolvedColumns()
Section titled “getResolvedColumns()”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>[]Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
params | Partial<ExportParams> |
formatCsv()
Section titled “formatCsv()”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): stringParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
data | Record<string, unknown>[] | |
params | FormatCsvParams | |
options | CsvOptions |
Example
Section titled “Example”const csv = exporter.formatCsv(exporter.export());await navigator.clipboard.writeText(csv);formatExcel()
Section titled “formatExcel()”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): stringParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
data | Record<string, unknown>[] | |
params | FormatExcelParams |
exportCsv()
Section titled “exportCsv()”Export data to CSV format.
exportCsv(params: Partial<ExportParams>): voidParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
params | Partial<ExportParams> | Optional export parameters |
exportExcel()
Section titled “exportExcel()”Export data to Excel format (XML Spreadsheet).
exportExcel(params: Partial<ExportParams>): voidParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
params | Partial<ExportParams> | Optional export parameters |
exportJson()
Section titled “exportJson()”Export data to JSON format.
exportJson(params: Partial<ExportParams>): voidParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
params | Partial<ExportParams> | Optional export parameters |
isExporting()
Section titled “isExporting()”Check if an export is currently in progress.
isExporting(): booleanReturns
Section titled “Returns”boolean - Whether export is in progress
getLastExport()
Section titled “getLastExport()”Get information about the last export.
getLastExport(): object | nullReturns
Section titled “Returns”object | null - Export info or null if no export has occurred