Row background colors when Print
Row background colors when Print
I am using CreatedRow callback to change the row background color (css) if certain values appears.
if (data[9] == "Pickup Only" && data[10] == 'none') { $('td', row).addClass('blue-class'); }
It shows the background color on browser but when I print it does not show colors.
I am using following print button code:
{
extend: 'print',
autoPrint: false,
exportOptions: {
columns: ':visible',
stripHtml: true,
},
customize: function ( win ) {
$(win.document.body)
.css( 'font-size', '10pt' )
.prepend(
'<img src="images/img1.jpg" style="position:absolute; opacity: 0.5; width:7% ; height:7% ; top:0; left:20;" />'
);
$(win.document.body).find( 'table' )
.addClass( 'compact' )
.css( 'font-size', 'inherit' );
$(win.document.body).find('h1').css('text-align','center');
}
}
This discussion has been closed.
Answers
This SO thread should get you going, there's an example on that page.
Colin
I tried following the example, but it threw an error
We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
Cheers,
Colin
If the background is showing on screen but not printing, isn't this just a simple case of the fact that the default in all browsers is not to print background colors? Unless I'm missing something, the user would have to change that option in their browser. You can't control it via code.
That's true if you use the browser's print functionality. However, if you're using paging, then that would only print the current page. These questions refer to using the Buttons' print functionality, which will print all rows from all pages, and would need a code-level solution,
Colin
This question is a few months old and doesn't appear to be answered.. I posted
a similar issue today.
I found that using bootstrap4 is the issue.. If I use the default Datatables styling everything works as expected.. My app used Bootstrap4 so I need this to work.. My example has test code
See my first reply - that points to a SO thread showing how to do it.
Colin
@colin I'm using customize and format which is what you show in the SO thread.. So my approach in the customize and fomat functions incorrect in setting the color. It does work without bootstrap(ie using jqueryui). See my jsfiddle example
you can run the test there to see what I'm experiencing with both bootstrap 3 and 4in this scenerio..
The example you show is using pdfHtml5.. I'm just using the print button..
@colin I did a test with pdfHtml5 and that does work.. however, using just the print bottom is where I'm having the issue.. I do have background graphics enabled in chrome..