{hero}

print

Since: Buttons 1.0.0

Button show a printable view of the table's data.
Please note - this property requires the Buttons extension for DataTables.

Description

The print view button will take a copy of the data displayed in a table (based on the selector options given in the exportOptions parameter) and construct a new, temporary, table that is shown in a new window. The browser's print command is then automatically invoked (although this can be disabled - see the autoPrint option below) and finally the window closed when the print action has been completed or cancelled by the end user.

The constructed table does not retain the full information from the original table (table row and cell classes are not copied across for example), but the stylesheets from the original document are copied to the print document so the basic styling of the table can be retained.

Customisation of the printed view is available through the title and message options for simple description strings and through the customize option for complete control over the generated document (allowing, for example images to be added, etc).

Please note that the print button will set the decodeEntities option of buttons.exportData() to false to prevent XSS attacks.

Options

This button can have the following options set in its configuration object to customise its actions and display, in addition to those options which are available for all buttons (e.g. buttons.buttons.text):

Examples

DataTables initialisation: Show a print button:

new DataTable('#myTable', {
	layout: {
		topStart: {
			buttons: ['print']
		}
	}
});

DataTables initialisation: Disable auto display of the print dialogue box:

new DataTable('#myTable', {
	layout: {
		topStart: {
			buttons: [
				{
					extend: 'print',
					text: 'Print current page',
					autoPrint: false
				}
			]
		}
	}
});

DataTables initialisation: Use the exportOptions to print only the current DataTable page:

new DataTable('#myTable', {
	layout: {
		topStart: {
			buttons: [
				{
					extend: 'print',
					text: 'Print current page',
					exportOptions: {
						modifier: {
							page: 'current'
						}
					}
				}
			]
		}
	}
});