changes for print

This commit is contained in:
Roshan 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
}
?>

View File

@ -4,7 +4,7 @@
<head>
<title><?php echo myLang($this->config->item("ProjectTitle")); ?> >> <?php echo isset($pageTitle)?$pageTitle:" | Dashboard"; ?></title>
<title><?php echo myLang($this->config->item("ProjectTitle")); ?> >> <?php echo isset($pageTitle) ? $pageTitle : " | Dashboard"; ?></title>
<meta charset="utf-8">
@ -39,6 +39,105 @@
<link rel="stylesheet" href="<?php echo base_url(); ?>plugins/select2-bootstrap4-theme/select2-bootstrap4.min.css">
<link rel="stylesheet" href="<?php echo base_url(); ?>plugins/bstreeview/css/bstreeview.min.css">
<link rel="stylesheet" href="<?php echo base_url(); ?>dist/css/bbnepalcustom.css">
<!-- CSV File create -->
<script>
// function exportTableToCSVNew(filename) {
// const csvRows = [];
// const rows = document.querySelectorAll("#dataTable tr");
// for (const row of rows) {
// const cols = row.querySelectorAll("td, th");
// const csvRow = [];
// for (const col of cols) {
// // csvRow.push(col.innerText.replace(/,/g, '')); // Remove commas for CSV
// csvRow.push(col.innerText); // Include empty cells as ''
// }
// 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);
// }
function exportTableToCSV(filename) {
const csvRows = [];
const rows = document.querySelectorAll("#dataTable tr");
let rowSpanTracker = {};
for (const row of rows) {
const cols = row.querySelectorAll("td, th");
const csvRow = [];
let currentRow = [];
for (const col of cols) {
const colSpan = parseInt(col.getAttribute('colspan') || 1);
const rowSpan = parseInt(col.getAttribute('rowspan') || 1);
const cellValue = col.innerText.replace(/,/g, '').trim() || '';
// Handle row span by marking the cells
if (rowSpan > 1) {
for (let r = 0; r < rowSpan; r++) {
if (!rowSpanTracker[r]) rowSpanTracker[r] = {};
rowSpanTracker[r][currentRow.length] = true; // Mark this position for rowspan
}
}
// Fill CSV row with values
for (let i = 0; i < colSpan; i++) {
if (i === 0 && !rowSpanTracker[currentRow.length]?.[currentRow.length]) {
csvRow.push(cellValue); // First instance of the cell value
} else {
csvRow.push(''); // Other instances as empty
}
}
}
// Fill the empty spaces due to rowspan
if (rowSpanTracker[currentRow.length]) {
currentRow.forEach((_, index) => {
if (!rowSpanTracker[currentRow.length]?.[index]) {
csvRow[index] = ''; // Fill in empty spaces
}
});
}
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 -->
<!-- Override Defaults By Prajwal -->
<style>
body {
@ -299,14 +398,14 @@
width: 100%;
float: left;
}
}
.narration_display
{
.narration_display {
font-style: italic;
}
.text-bold .currency
{
.text-bold .currency {
font-weight: 600 !important;
}
</style>

View File

@ -151,9 +151,11 @@
</div>
</div>
<div class="btn-group">
<button type="submit" class="btn btn-warning btn-sm " data-toggle="dropdown" data-offset="-52">
<!-- <button type="submit" 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>

Binary file not shown.