Skip to content

Export Plugin

The Export plugin lets users download grid data as CSV, JSON, or other formats with a single click or API call. Great for reporting, data backup, or letting users work with data in Excel.

import '@toolbox-web/grid/features/export';

Enable the feature and call exportCsv() or exportJson() when you’re ready to download. You can also combine it with the selection feature to export only selected rows.

import { queryGrid } from '@toolbox-web/grid';
const grid = queryGrid('tbw-grid');
grid.gridConfig = {
columns: [
{ field: 'name', header: 'Name' },
{ field: 'email', header: 'Email' },
{ field: 'department', header: 'Department' }
],
features: {
export: {
fileName: 'employees',
includeHeaders: true,
},
},
};
// Trigger export via button click
document.getElementById('export-btn').addEventListener('click', () => {
const plugin = grid.getPluginByName('export');
plugin.exportCsv();
});
Include headers Include column headers in export
Visible only Export only visible columns
Selected only Export only selected rows

Export all visible data to CSV. Toggle “Selected only” and select some rows to export just those.

OptionTypeDefaultDescription
fileNamestring'export'Base filename (without extension)
includeHeadersbooleantrueInclude column headers in export
onlyVisiblebooleantrueExport only visible columns
onlySelectedbooleanfalseExport only selected rows (requires SelectionPlugin)

The ExportPlugin provides methods for exporting data with fine-grained control over which columns and rows to include. Like the ClipboardPlugin, it accepts columns and rowIndices parameters so you can export exactly the data you need.

const exportPlugin = grid.getPluginByName('export');
// Export all visible data to CSV
exportPlugin.exportCsv();
// Export to Excel XML
exportPlugin.exportExcel();
// Export to JSON
exportPlugin.exportJson();

Export with Column/Row Control (ExportParams)

Section titled “Export with Column/Row Control (ExportParams)”
const exportPlugin = grid.getPluginByName('export');
// Export specific columns
exportPlugin.exportCsv({
columns: ['name', 'email', 'department'],
fileName: 'contacts',
includeHeaders: true,
});
// Export specific rows
exportPlugin.exportCsv({
rowIndices: [0, 3, 7],
fileName: 'selected-employees',
});
// Export specific columns from specific rows
exportPlugin.exportExcel({
columns: ['name', 'salary'],
rowIndices: [0, 1, 2],
fileName: 'salary-report',
});
OptionTypeDefaultDescription
fileNamestringconfig valueFile name (without extension)
columnsstring[]-Specific column fields to export
rowIndicesnumber[]-Specific row indices to export
includeHeadersbooleanconfig valueInclude column headers in export
processCell(value, field, row) => any-Custom cell value processor
processHeader(header, field) => string-Custom header processor
Event Log:
EventDetailDescription
export-complete{ format, fileName, rowCount, columnCount }Fired after an export completes
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