add export excel and pdf report director
This commit is contained in:
@@ -17,6 +17,8 @@ class BigdataResume {
|
||||
async initEvents() {
|
||||
await this.initBigdataResumeTable();
|
||||
// this.handleSearch();
|
||||
await this.handleExportPDF();
|
||||
await this.handleExportToExcel();
|
||||
}
|
||||
|
||||
async initBigdataResumeTable() {
|
||||
@@ -114,6 +116,100 @@ class BigdataResume {
|
||||
});
|
||||
}
|
||||
|
||||
async handleExportToExcel() {
|
||||
const button = document.getElementById("btn-export-excel");
|
||||
if (!button) {
|
||||
console.error("Button not found: #btn-export-excel");
|
||||
return;
|
||||
}
|
||||
|
||||
let exportUrl = button.getAttribute("data-url");
|
||||
|
||||
button.addEventListener("click", async () => {
|
||||
button.disabled = true;
|
||||
try {
|
||||
const response = await fetch(`${exportUrl}`, {
|
||||
method: "GET",
|
||||
credentials: "include",
|
||||
headers: {
|
||||
Authorization: `Bearer ${document
|
||||
.querySelector('meta[name="api-token"]')
|
||||
.getAttribute("content")}`,
|
||||
},
|
||||
});
|
||||
if (!response.ok) {
|
||||
console.error("Error fetching data:", response.statusText);
|
||||
button.disabled = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// Convert response to Blob and trigger download
|
||||
const blob = await response.blob();
|
||||
const url = window.URL.createObjectURL(blob);
|
||||
const a = document.createElement("a");
|
||||
a.href = url;
|
||||
a.download = "laporan-pimpinan.xlsx";
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
document.body.removeChild(a);
|
||||
window.URL.revokeObjectURL(url);
|
||||
} catch (error) {
|
||||
console.error("Error fetching data:", error);
|
||||
button.disabled = false;
|
||||
return;
|
||||
} finally {
|
||||
button.disabled = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async handleExportPDF() {
|
||||
const button = document.getElementById("btn-export-pdf");
|
||||
if (!button) {
|
||||
console.error("Button not found: #btn-export-pdf");
|
||||
return;
|
||||
}
|
||||
|
||||
let exportUrl = button.getAttribute("data-url");
|
||||
|
||||
button.addEventListener("click", async () => {
|
||||
button.disabled = true;
|
||||
try {
|
||||
const response = await fetch(`${exportUrl}`, {
|
||||
method: "GET",
|
||||
credentials: "include",
|
||||
headers: {
|
||||
Authorization: `Bearer ${document
|
||||
.querySelector('meta[name="api-token"]')
|
||||
.getAttribute("content")}`,
|
||||
},
|
||||
});
|
||||
if (!response.ok) {
|
||||
console.error("Error fetching data:", response.statusText);
|
||||
button.disabled = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// Convert response to Blob and trigger download
|
||||
const blob = await response.blob();
|
||||
const url = window.URL.createObjectURL(blob);
|
||||
const a = document.createElement("a");
|
||||
a.href = url;
|
||||
a.download = "laporan-pimpinan.pdf";
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
document.body.removeChild(a);
|
||||
window.URL.revokeObjectURL(url);
|
||||
} catch (error) {
|
||||
console.error("Error fetching data:", error);
|
||||
button.disabled = false;
|
||||
return;
|
||||
} finally {
|
||||
button.disabled = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
handleSearch() {
|
||||
document.getElementById("search-btn").addEventListener("click", () => {
|
||||
let searchValue = document.getElementById("search-box").value;
|
||||
|
||||
Reference in New Issue
Block a user