View as Markdown

Export and print

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.scope is 'all' (every page, the default) or 'page' (the current page); printing.hierarchy picks which detail rows and child grids print: 'expanded' (the default), 'all' or 'none'. printing.detail (or the detail option of print()) is the export detail hook: return { text } lines (or a child model) for a row's detail template, null for none; React detail templates never print by themselves. print() options override printing.
  • onBeforePrint runs before the browser's print dialog and cancels it with preventDefault(); onAfterPrint follows the window's afterprint event.
  • printable: false on a column (a DataGridColumn option) 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 demo

Excel, 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.

Order
Customer
Product
Qty
Amount
Discount
Category
Status
Name
City
Country: France - 100 items
ORD-10000
Jun Park
Reims
Green tea
1
$8.33
10%
Loose-leaf tea
Shipped
ORD-10004
Ines Duarte
Lyon
Espresso beans
7
$110.08
15%
Coffee beans
Shipped
ORD-10006
Goran Petrov
Lyon
Grinder
2
$258.00
0%
Brewing equipment
Pending
ORD-10010
Bao Nguyen
Lyon
Pour-over kit
12
$504.00
0%
Brewing equipment
Pending
ORD-10012
Goran Petrov
Lyon
Pour-over kit
11
$392.70
15%
Brewing equipment
Shipped
ORD-10020
Ines Duarte
Reims
Pour-over kit
10
$399.00
5%
Brewing equipment
Pending
ORD-10022
Hana Sato
Lyon
Oolong tea
11
$140.25
0%
Loose-leaf tea
Shipped
ORD-10033
Jun Park
Lyon
Kettle
5
$324.50
0%
Brewing equipment
Shipped
ORD-10036
Goran Petrov
Reims
Kettle
6
$369.93
5%
Brewing equipment
Shipped
ORD-10039
Jun Park
Lyon
Filter beans
12
$151.20
10%
Coffee beans
Pending
ORD-10040
Farah Aziz
Lyon
Grinder
8
$877.20
15%
Brewing equipment
Pending
ORD-10048
Ines Duarte
Reims
Green tea
6
$47.18
15%
Loose-leaf tea
Pending
ORD-10049
Elif Kaya
Lyon
Kettle
5
$324.50
0%
Brewing equipment
Shipped
ORD-10061
Hana Sato
Lyon
Kettle
12
$778.80
0%
Brewing equipment
Pending
ORD-10063
Goran Petrov
Lyon
Green tea
7
$61.51
5%
Loose-leaf tea
Shipped
ORD-10066
Bao Nguyen
Lyon
Green tea
7
$55.04
15%
Loose-leaf tea
Shipped
ORD-10071
Aiko Tan
Reims
Oolong tea
8
$96.90
5%
Loose-leaf tea
Pending
ORD-10076
Bao Nguyen
Reims
Green tea
1
$7.86
15%
Loose-leaf tea
Shipped
ORD-10082
Hana Sato
Lyon
Oolong tea
1
$10.84
15%
Loose-leaf tea
Pending
Region
Country
Target
Stretch (+10%)
Europe
France
$180,000
$198,000
Europe
Germany
$210,000
$231,000
Europe
Portugal
$95,000
$104,500
Asia
Japan
$240,000
$264,000
Asia
Malaysia
$120,000
$132,000
No events yet.