Professional Documents
Culture Documents
Html
<script src="./public/js/busqueda_masiva.js"></script>
Js
busqueda = () => {
document.querySelector('#plantilla_busqueda').addEventListener('click', plan
tilla);
document.querySelector('#carga_csv').addEventListener('submit', buscar_datos
);
document.querySelector('#exportar_csv').addEventListener('click', csv);
}
csv = () => {
const dataTable = document.getElementById("dataTable");
const exporter = new TableCSVExporter(dataTable);
const csvOutput = exporter.convertToCSV();
const csvBlob = new Blob([csvOutput], { type: "text/csv" });
const blobUrl = URL.createObjectURL(csvBlob);
const anchorElement = document.createElement("a");
anchorElement.href = blobUrl;
anchorElement.download = "table-export.csv";
anchorElement.click();
setTimeout(() => {
URL.revokeObjectURL(blobUrl);
}, 500);
}
class TableCSVExporter {
constructor(table, includeHeaders = true) {
this.table = table;
this.rows = Array.from(table.querySelectorAll("tr"));
convertToCSV() {
const lines = [];
const numCols = this._findLongestRowLength();
lines.push(line);
}
return lines.join("\n");
}
_findLongestRowLength() {
return this.rows.reduce((l, row) => row.childElementCount > l ? row.chil
dElementCount : l, 0);
}
static parseCell(tableCell) {
let parsedValue = tableCell.textContent;
return parsedValue;
}
}