changes for print

This commit is contained in:
2024-09-29 17:46:26 +05:45
parent 684e01bf48
commit 60f4c75eb0
4 changed files with 114 additions and 104 deletions

View File

@ -56,9 +56,11 @@
</div>
</div>
<div class="btn-group">
<button type="submit" onclick="exportTableToCSV('table_data.csv')" class="btn btn-warning btn-sm " data-toggle="dropdown" data-offset="-52">
<!-- <button type="submit" onclick="exportTableToCSVNew('accounts_data.csv')" class="btn btn-warning btn-sm " data-toggle="dropdown" data-offset="-52">
Export
</button>
</button> -->
<button class="btn btn-warning btn-sm " onclick="exportTableToCSV('accounts_data.csv')">Export to CSV</button>
<!-- <div class="dropdown-menu" role="menu">
<a href="#" class="dropdown-item">Export</a>
<a href="#" class="dropdown-item">Pdf</a>
@ -232,100 +234,7 @@
});
</script>
<!-- csv printing -->
<!-- <script type="text/javascript">
function tableToCSV() {
// Variable to store the final csv data
let csv_data = [];
// Get each row data
let rows = document.getElementsByTagName('tr');
for (let i = 0; i < rows.length; i++) {
// Get each column data
let cols = rows[i].querySelectorAll('td,th,span,a');
// Stores each csv row data
let csvrow = [];
for (let j = 0; j < cols.length; j++) {
// Get the text data of each cell
// of a row and push it to csvrow
csvrow.push(cols[j].innerText);
}
// Combine each column value with comma
csv_data.push(csvrow.join(","));
}
// Combine each row data with new line character
csv_data = csv_data.join('\n');
// Call this function to download csv file
downloadCSVFile(csv_data);
}
function downloadCSVFile(csv_data) {
// Create CSV file object and feed
// our csv_data into it
CSVFile = new Blob([csv_data], {
type: "text/csv"
});
// Create to temporary link to initiate
// download process
let temp_link = document.createElement('a');
// Download csv file
temp_link.download = "GfG.csv";
let url = window.URL.createObjectURL(CSVFile);
temp_link.href = url;
// This link should not be displayed
temp_link.style.display = "none";
document.body.appendChild(temp_link);
// Automatically click the link to
// trigger download
temp_link.click();
document.body.removeChild(temp_link);
} -->
</script>
<script>
function exportTableToCSV(filename) {
const csvRows = [];
const rows = document.querySelectorAll(".longdataTable tr"); // Use the specific class
for (const row of rows) {
const cols = row.querySelectorAll("td, th");
const csvRow = [];
for (const col of cols) {
csvRow.push(col.innerText); // Get text content of each cell
}
csvRows.push(csvRow.join(",")); // Join cells with commas
}
// Create a CSV string
const csvString = csvRows.join("\n");
// Create a Blob for the CSV string
const blob = new Blob([csvString], { type: "text/csv" });
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = filename;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
}
</script>
<!-- csv printing ends -->
<?php
}
?>