Merge branch 'administativePages' into 'dev'
add download csv resumo operacao table functionality See merge request kluppsoftware/smart-energia-web!70
This commit is contained in:
commit
3556ef31da
@ -36,6 +36,39 @@ export default function ResumoOperacao({tableData, clientsData, userName, client
|
|||||||
setUnidade(event.target.value);
|
setUnidade(event.target.value);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function downloadCSVFile(csv, filename) {
|
||||||
|
const csv_file = new Blob([csv], {type: "text/csv"});
|
||||||
|
|
||||||
|
const download_link = document.createElement("a");
|
||||||
|
|
||||||
|
download_link.download = filename;
|
||||||
|
|
||||||
|
download_link.href = window.URL.createObjectURL(csv_file);
|
||||||
|
|
||||||
|
download_link.style.display = "none";
|
||||||
|
|
||||||
|
document.body.appendChild(download_link);
|
||||||
|
|
||||||
|
download_link.click();
|
||||||
|
}
|
||||||
|
|
||||||
|
function htmlToCSV(html, filename) {
|
||||||
|
const data = [];
|
||||||
|
const rows = document.querySelectorAll("table tr");
|
||||||
|
|
||||||
|
for (let i = 0; i < rows.length; i++) {
|
||||||
|
const row = [], cols: any = rows[i].querySelectorAll("td, th");
|
||||||
|
|
||||||
|
for (let j = 0; j < cols.length; j++) {
|
||||||
|
row.push(cols[j].innerText);
|
||||||
|
}
|
||||||
|
|
||||||
|
data.push(row.join(","));
|
||||||
|
}
|
||||||
|
|
||||||
|
downloadCSVFile(data.join("\n"), filename);
|
||||||
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (unidade!=='' || month!==''){
|
if (unidade!=='' || month!==''){
|
||||||
api.post('/operation/summary', {
|
api.post('/operation/summary', {
|
||||||
@ -128,10 +161,10 @@ export default function ResumoOperacao({tableData, clientsData, userName, client
|
|||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
<div className='btn'>
|
<div className='btn'>
|
||||||
<CSVLink data={csvData} filename="Arquivo_Teste_Smart_Energia">
|
<BasicButton title='Baixar CSV' onClick={() => {
|
||||||
|
const html = document.querySelector("table").outerHTML;
|
||||||
<BasicButton title='Baixar CSV' onClick={() => console.log()}/>
|
htmlToCSV(html, "resumo_operacao.csv");
|
||||||
</CSVLink>
|
}}/>
|
||||||
</div>
|
</div>
|
||||||
</TableView>
|
</TableView>
|
||||||
)
|
)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user