i'm using a custom component to do a print button that prints items inside my listview. this is my iframe code
<script>
// Function to generate cart items and total for printing
function generatePrintContent() {
// Replace this section with your dynamic cart item generation
let cartItems = "";
for (let i = 0; i < listView1.data.length; i++) {
const title = listView1.data[i].retoolInternal_rowKey.title;
const size = listView1.data[i].retoolInternal_rowKey.unit_of_measure.toLowerCase();
const qty = document.querySelector("#textInput30").value;
const price = (listView1.data[i].retoolInternal_rowKey.selling_price * parseFloat(textInput31)).toLocaleString();
cartItems += `<tr>
<td>${title} (${size})</td>
<td class="alignright">$ ${price}</td>
</tr>`;
}
// Get the total value
const total = statistic4.value;
// Generate the HTML content for printing
const printContent = `
<h2>Cart Items</h2>
<table class="invoice-items">
<tbody>
${cartItems}
<tr class="total">
<td class="alignright" width="80%">Total</td>
<td class="alignright">$ ${total}</td>
</tr>
</tbody>
</table>
`;
return printContent;
}
// Function to handle the print button click
function printCart() {
const printWindow = window.open('', '', 'width=600,height=600');
printWindow.document.open();
printWindow.document.write(`
<html>
<head>
<title>Print Cart</title>
</head>
<body>
${generatePrintContent()}
</body>
</html>
`);
printWindow.document.close();
printWindow.print();
printWindow.close();
}
// Add an event listener to the Print button
document.getElementById("printButton").addEventListener("click", printCart);
</script>
please can someone help me out.
![image|690x236](upload://rhOHC4C0IhwVYLtwzl5aIBacEIv.png)