Call Print from a custom button
Call Print from a custom button
Hi all,
Is it possible to call the print function from a custom button? We have (like most) our own UI and buttons/actions on the page and would like to tie one of them to the print action. Can't figure out how to do this.
thanks
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Try like this:
The code from @BoltBait would print the entire window, so its probably not what you want..
My question is... why do you want to create another button, just to trigger the click on a button?
I was in a situation where I wanted to highly customize the button, so what I did was just use the API to do it.
If you look at this screenshot, and this one, you can see that the "tool box" I created has the
copy,csv,pdf,-button print,excel,selectAll,selectNoneand even a-collectionwith thecolumnsTogglein it, as well as some custom buttons..You can basically just style the buttons as you want by adding CSS classes with
className, then move the buttons where you want usingtable.buttons( 0, null ).container().appendTo( '#some-container' );It works perfectly fine..
Heres my exact code:
Alternatively, you could do something super cheesy, like create the print button, and add a class name (EG:
print-button) usingclassName, then use CSS to hide that button, and create another button that will$('button.print-button').trigger('click'), but thats super cheesy.. especially since you can accomplish just about everything just using the awesome DT API!JLinux,
That's perfect. Great bit of code and EXACTLY what I was looking for (we use bootstrap also so even better).
thanks
Awesome! :) Glad I could help.
Whenever I try to find a "work around" for something in DT, I usually just try to realize that I probably am not the first person to run into that issue, and @allan has thought of most everything, so theres probably a very reasonable solution