Tabletools - print only selected rows
Tabletools - print only selected rows
I'd like to be able to print only the currently selected rows, when clicking the tabletools print button. I see this has been asked before and there was some discussion about implementing it - https://www.datatables.net/forums/discussion/3755/tabletools-multirow-select-print-only-selected-rows - but I looked through the docs and couldn't find a way.
Anyone know if this has been added and I just missed it? If it hasn't been added, maybe there's a way I can run "before print" and "after print" functions that will handle the hide and show for me?
Answers
If anyone reads this in the future, I came up with a somewhat convoluted way to do it. I start with a hidden column that acts as a flag, noting whether the entire row should be hidden on print.
I also hide the normal print button using CSS, and add one of my own with class ".printRows".
When that button is clicked, I set the flag for all rows that aren't selected, and then trigger a click on the normal print button.
Finally, I listen for escape keypress so I can unhide the rows when print is complete.
There is apparently new functionality to address this situation:
https://datatables.net/extensions/buttons/examples/print/select.html
I wanted something similar, I wanted it to print the selected rows if any were selected, and if none were, print all rows, but only have one button.
I ended up doing the following:
Demo here
P.S. For some reason, I couldn't a grip on the API instance within the
rows
closure, I triedthis
,this.api
, and a few other things, but it either threw an error saying that it didnt exist, or I couldnt call rows on null, so I ended up just executingnew $.fn.dataTable.Api( '#example' );
, which sucks, because I hate having to re-reference the CSS selector for the table. I triednew $.fn.dataTable.Api( this );
, and while it didn't throw any errors, it didn't work (It would never see any rows as selected)Maybe @allan can tell me what I was doing wrong