Skip to content

Instantly share code, notes, and snippets.

@rafaehlers
Last active April 17, 2024 19:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rafaehlers/c3028a16c0fa1546b7006f5802f209fd to your computer and use it in GitHub Desktop.
Save rafaehlers/c3028a16c0fa1546b7006f5802f209fd to your computer and use it in GitHub Desktop.
DataTables > Buttons > PDF > Show Image URLs
document.addEventListener('DOMContentLoaded', function() {
wp.hooks.addFilter( 'gk.datatables.options', 'dt-custom-code', function ( options ) {
options.buttons = options.buttons.map( button => {
if ( 'pdf' === button.extend ) {
const originalBodyFunction = button.exportOptions?.format?.body;
button.exportOptions = button.exportOptions || {};
button.exportOptions.format = button.exportOptions.format || {};
button.exportOptions.format.body = function ( data, row, column, node ) {
const output = originalBodyFunction ? originalBodyFunction( data, row, column, node ) : data;
return jQuery( data ).find( 'img' ).attr( 'src' ) ?? output;
};
}
return button;
} );
return options;
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment