Export and print
Print every row of the grid view without virtualization, all pages or the current page, with print events and a print stylesheet.
api.print() and the toolbar 'print' item print the grid. The
grid renders a print projection: one static table of every row in the print
scope, with stacked headers, group captions, aggregates and detail or
child-grid tables. Virtualization does not apply, so printing a large grid
prints all of its rows.
<DataGrid
ref={api}
data={orders}
columns={columns}
toolbar={['print']}
printing={{ scope: 'page', hierarchy: 'expanded' }}
onBeforePrint={(event) => {
if (event.scope === 'all' && !confirm('Print every page?')) event.preventDefault();
}}
onAfterPrint={() => console.log('printed')}
/>
// print() options override `printing`; resolves false when prevented
const printed = await api.current?.print({ scope: 'all' });
printing.scopeis'all'(every page, the default) or'page'(the current page);printing.hierarchypicks which detail rows and child grids print:'expanded'(the default),'all'or'none'.printing.detail(or thedetailoption ofprint()) is the exportdetailhook: return{ text }lines (or a childmodel) for a row's detail template,nullfor none; React detail templates never print by themselves.print()options overrideprinting.onBeforePrintruns before the browser's print dialog and cancels it withpreventDefault();onAfterPrintfollows the window'safterprintevent.printable: falseon a column (aDataGridColumnoption) leaves it out of print; the pager and toolbar never print, also when the page is printed from the browser menu.- With focus in the grid, Ctrl+P (Cmd+P on macOS) prints the grid instead of the page.
The print document for 10,000 rows by 20 columns reaches the print dialog
within one second. Nothing print-related runs during render: the print
document is built on demand in the browser, and print() resolves false
outside a browser, so server rendering is unaffected.
Export and print
Open demoExcel, PDF and CSV export of 10,000 grouped rows with stacked headers, aggregates, lookup text, templates, hidden columns, selected rows, detail blocks, a second grid in the same workbook, an embedded PDF font and a server export route; writers load on demand; print of every row of the scope.
API reference
See DataGridPrinting,
DataGridPrintOptions,
DataGridBeforePrintEvent
and DataGridAfterPrintEvent
in the API reference.