Having a hidden table with thousands of rows can cause performance issues, especially on slower devices. A better solution would be to use JavaScript to fetch the non-paginated data when the print button is clicked, and then generate a printable version of the table on the fly. This way, you only load the data when it's needed, and you don't have to worry about performance issues caused by a large hidden table.
Here's an example of how you could implement this:
- Add a button to your page that triggers the print function:
<button id="print-button">Print</button>
- Add a script that fetches the non-paginated data and generates a printable table:
<script>
document.getElementById('print-button').addEventListener('click', function() {
// Fetch the non-paginated data
fetch('/path/to/non-paginated-data')
.then(response => response.json())
.then(data => {
// Generate the printable table
let table = '<table>';
data.forEach(row => {
table += '<tr>';
table += '<td>' + row.col1 + '</td>';
table += '<td>' + row.col2 + '</td>';
// ... more columns ...
table += '</tr>';
});
table += '</table>';
// Open the print dialog with the printable table
let printWindow = window.open('', 'Print', 'height=600,width=800');
printWindow.document.write(table);
printWindow.document.close();
printWindow.focus();
printWindow.print();
printWindow.close();
});
});
</script>
- Add a route to your Laravel application that returns the non-paginated data:
Route::get('/path/to/non-paginated-data', function() {
return Model::get();
});
With this solution, you only load the non-paginated data when the print button is clicked, and you generate a printable version of the table on the fly. This way, you don't have to worry about performance issues caused by a large hidden table.