How can I invoke the browser's print function to print a table?
Hello @Cesar Ge
Here is a general solution, using CSS only, which I have verified to work.
@media print { body { visibility: hidden; } #section-to-print { visibility: visible; position: absolute; left: 0; top: 0; }}
Replace the #section-to-print with a container Id or grid id to which content you want to print.
You can take a reference of a working solution in below links -
Code LinkBrowser Preview Link
In preview link Use the browser's Print command (e.g. control-P or command-P). The print preview should show only the given id content. Everything else should not appear.
I hope it'll help you.
ThanksDeep
Yeah we can @Cesar Ge
Add this JS in Scripts
function printSpecificContainer(contId) {
var container = document.getElementById(contId); // Get the container
if (container) {
var printWindow = window.open('', '_blank'); // Open a new blank window
var styles = document.head.innerHTML; // Get all styles from the main document
printWindow.document.write('Print');
printWindow.document.write(styles); // Include the styles in the print window
printWindow.document.write('');
printWindow.document.write(container.innerHTML); // Write the container's content
printWindow.document.close(); // Close the document to finish writing
printWindow.focus(); // Focus on the print window
printWindow.print(); // Trigger the print dialog
printWindow.close(); // Optionally close the print window after printing
} else {
alert("Container not found!");
}
Then In Screen's property add the same as required script
In Print on click call, add js with the grid's widget id as input parameter and call the print function: printSpecificContainer($parameters.contId);
Hope it will help you
Regards
Murali
I will give it a try. Thank you very much for your help.
Hi @Murali Manoharan V ,
When I execute it, it doesn't print what I need. Do you know how to fix it? Thank you for your help.
Here is the content of the gridI want to print.
What I want to print is a grid, not a table. Thank you again for your help and I look forward to your response.
There are a few versatile solutions on the forge, depending on your use case.
Check out PrintJS and Ultimate PDF
Hi @Cesar Ge
Inside the button's On Click screen action, add a JavaScript node and include the following code to trigger the browser's print functionality:
window.print();
I want to call the browser's print function to print this grid. Do you know how to do it with JS? If you know other methods, please let me know as well. Thank you for your help.
When I use window.print(), it prints the entire page, but I only want to print this grid.
hi. i try it . only got a blank print page on app .