DataTables Print - How to display images and URLs

By default, DataTables's Print button, doesn't include images or link URLs.

Data table showing a cat image, a URL to wikipedia.org, and an Edit Entry link

Print preview of a GravityKit demo table with file and URL details, options to save as PDF or print

With the help of this code snippet below, images and URLs will be visible when the page is printed.

document.addEventListener('DOMContentLoaded', function() {
	wp.hooks.addFilter( 'gk.datatables.options', 'dt-custom-code', function ( options ) {
		options.buttons = options.buttons.map( button => {
			if ( 'print' === button.extend ) {
				button.exportOptions = {
					stripHtml: false
				}
			}
			return button;
		} );	
		return options;
	} );
});

DataTables Print example showing a table with a cat image, website link, and edit entry URL in GravityKit demo

This JavaScript code should be copied and pasted, as it is, on the Custom JavaScript editor that sits inside View Editor > View Settings metabox > Custom Code tab.

Custom JavaScript section showing code to modify DataTables print options in GravityView settings

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us