Skip to content

Print Plugin

The Print Plugin enables printing the full grid content by temporarily disabling virtualization and applying print-optimized styles. It handles large datasets gracefully with configurable row limits.

  • Print Layout Mode - Optimized CSS styles for printing
  • Page Orientation - Portrait or landscape orientation
  • Row Limits - Configurable maximum rows with confirmation dialog for large datasets
  • Toolbar Button - Optional print button in grid header
  • Title & Timestamp - Optional print header with customizable title and timestamp
  • Column Hiding - Mark columns as printHidden to exclude from print output
import '@toolbox-web/grid/features/print';

Use the controls to try different orientations, toggle title/timestamp, isolated printing, and the toolbar button. Enable “Toolbar button” to add a print icon to the grid header (requires shell.header config).

import { queryGrid } from '@toolbox-web/grid';
import '@toolbox-web/grid/features/print';
const grid = queryGrid('tbw-grid');
grid.gridConfig = {
columns: [
{ field: 'name', header: 'Name' },
{ field: 'department', header: 'Department' },
{ field: 'salary', header: 'Salary' },
],
features: {
print: {
title: 'Employee Report',
includeTitle: true,
includeTimestamp: true,
},
},
};
// Programmatic print
const plugin = grid.getPluginByName('print');
await plugin.print();

See PrintConfig for the full list of options and defaults.

Use the printHidden column property to exclude specific columns from print output. This is useful for hiding action buttons, interactive elements, or columns that aren’t relevant on paper.

import { queryGrid } from '@toolbox-web/grid';
const grid = queryGrid('tbw-grid');
grid.gridConfig = {
columns: [
{ field: 'id', header: 'ID' },
{ field: 'name', header: 'Name' },
{ field: 'email', header: 'Email' },
{ field: 'actions', header: 'Actions', printHidden: true }, // Hidden when printing
],
features: { print: true },
};

The printHidden property:

  • Temporarily hides columns when print() is called
  • Automatically restores column visibility after printing
  • Preserves the original hidden state (if a column was already hidden, it stays hidden)
  • Works independently of the VisibilityPlugin

Two separate options control large dataset behavior:

  • warnThreshold - Shows a confirmation dialog when row count exceeds this value, letting users consent to a potentially slow print operation
  • maxRows - Hard-limits the printed rows to this number (excess rows are not rendered)
// Warn at 500+ rows, but print all if confirmed
features: { print: { warnThreshold: 500 } }
// Hard limit to 100 rows (no warning, just limits)
features: { print: { maxRows: 100, warnThreshold: 0 } }
// Warn at 500+ rows AND hard limit to 1000
features: { print: { warnThreshold: 500, maxRows: 1000 } }

The confirmation dialog shows:

  • Total row count
  • Note about hard limit (if maxRows is set)
  • Option to proceed or cancel

The plugin emits events during the print lifecycle:

Fired when print preparation begins:

grid.on('print-start', ({ rowCount, limitApplied, originalRowCount }) => {
console.log('Preparing rows:', rowCount);
console.log('Limit applied:', limitApplied);
if (limitApplied) {
console.log('Original count:', originalRowCount);
}
});

Fired when the print dialog closes:

grid.on('print-complete', ({ duration, rowCount }) => {
console.log('Dialog open for:', duration, 'ms');
console.log('Rows prepared:', rowCount);
});

Initiates the print process. Returns a Promise that resolves when printing completes.

const plugin = grid.getPluginByName('print');
// Basic print (prints entire page)
await plugin.print();
// With runtime overrides
await plugin.print({
title: 'Custom Report Title',
orientation: 'portrait',
});
// Isolated print - opens new window with only the grid
await plugin.print({ isolate: true });
ParameterTypeDescription
orientation'portrait' | 'landscape'Override page orientation
titlestringOverride print title
maxRowsnumberOverride maximum rows
isolatebooleanPrint with page isolation (hides all non-grid content)

When isolate: true is passed, the plugin uses CSS to hide everything on the page except the grid during printing. This is useful when:

  • The page has navigation, sidebars, or headers that shouldn’t appear in print
  • You want to print only the grid without surrounding UI
  • The grid is embedded in an application framework like Storybook, Angular, etc.
// Print just the grid, hiding all other page content
await plugin.print({ isolate: true });

How it works:

  1. A temporary @media print stylesheet is injected
  2. The stylesheet hides all elements except the grid (identified by its unique ID)
  3. After printing, the stylesheet is removed
  4. The grid stays in place with virtualization disabled, so ALL rows are printed

Returns true if a print operation is currently in progress.

if (plugin.isPrinting()) {
console.log('Print already in progress');
}

The plugin applies these CSS classes during printing:

ClassDescription
.print-portraitApplied when orientation is portrait
.print-landscapeApplied when orientation is landscape
.tbw-print-headerPrint header container
.tbw-print-header-titleTitle element
.tbw-print-header-timestampTimestamp element

Override print styles using CSS:

@media print {
tbw-grid.print-landscape {
/* Custom print styles */
font-size: 10pt;
}
tbw-grid.print-landscape .dg-cell {
border-color: #000;
}
}
  1. Disable Virtualization - Temporarily renders all rows (up to maxRows)
  2. Apply Print Styles - Adds print-mode CSS class and orientation class
  3. Add Print Header - Inserts title and timestamp (if configured)
  4. Trigger Print - Calls window.print()
  5. Cleanup - Restores virtualization and removes temporary elements

The Print Plugin uses standard browser printing APIs (window.print(), @media print) and works in all modern browsers:

  • Chrome / Edge (Chromium)
  • Firefox
  • Safari
  1. Set reasonable maxRows - Consider limiting to ~5000 rows to prevent browser hangs
  2. Use landscape for wide grids - More columns fit horizontally
  3. Test print preview - Use browser’s print preview to verify layout
  4. Custom titles - Provide meaningful titles for printed reports
  5. Use printHidden for interactive columns - Hide action buttons, checkboxes, etc.
  6. Use isolate: true - When other page content interferes with print layout

For simple use cases where you don’t need the full plugin, use the standalone printGridIsolated function:

import { queryGrid } from '@toolbox-web/grid';
import { printGridIsolated } from '@toolbox-web/grid/plugins/print';
const grid = queryGrid('tbw-grid');
await printGridIsolated(grid, {
orientation: 'landscape',
});

This function injects a temporary CSS stylesheet that hides everything except the target grid during printing. The grid must have an id attribute (DataGridElement auto-generates one if not explicitly set).

Note: Unlike the PrintPlugin, this function does NOT disable virtualization. If you need to print all rows, use the full PrintPlugin with isolate: true.

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