| Nama Dokumen Laporan Dampak Sosial, Ekonomi, dan Lingkungan |
Akses Dokumen |
|
Memuat data dokumen...
|
Memuat data dari server...
`;
try {
const response = await fetch(SE_GVIZ_URL);
if (!response.ok) throw new Error("Gagal mengambil data spreadsheet.");
const csvText = await response.text();
rawData = parseCSV(csvText);
filteredData = [...rawData];
renderTable();
} catch (error) {
tbody.innerHTML = `
Gagal memuat data. Pastikan spreadsheet diatur ke 'Anyone with the link can view'.
`;
}
}
window.seHandleSearch = function () {
const query = document.getElementById("seSearchInput").value.toLowerCase();
filteredData = rawData.filter(item => item.nama_dokumen.toLowerCase().includes(query));
currentPage = 1;
renderTable();
};
function renderTable() {
const tbody = document.getElementById("seDataBody");
tbody.innerHTML = "";
if (!filteredData || filteredData.length === 0) {
tbody.innerHTML = `
Dokumen tidak ditemukan.
`;
renderPagination();
return;
}
const start = (currentPage - 1) * rowsPerPage;
const end = start + rowsPerPage;
const pageData = filteredData.slice(start, end);
pageData.forEach(item => {
const tr = document.createElement("tr");
const safeTitle = item.nama_dokumen.replace(/'/g, "\\'");
tr.innerHTML = `
${item.nama_dokumen}
Lihat PDF
`;
tbody.appendChild(tr);
});
renderPagination();
}
function renderPagination() {
const totalRows = filteredData.length;
const totalPages = Math.ceil(totalRows / rowsPerPage);
const start = totalRows === 0 ? 0 : (currentPage - 1) * rowsPerPage + 1;
const end = Math.min(currentPage * rowsPerPage, totalRows);
document.getElementById("seInfo").innerText = `Menampilkan ${start}-${end} dari ${totalRows} dokumen`;
const controls = document.getElementById("seControls");
controls.innerHTML = "";
if (totalPages <= 1) return;
const prevBtn = document.createElement("button");
prevBtn.className = "se-page-btn";
prevBtn.innerText = "Prev";
prevBtn.disabled = currentPage === 1;
prevBtn.onclick = () => { currentPage--; renderTable(); };
controls.appendChild(prevBtn);
for (let i = 1; i <= totalPages; i++) {
const btn = document.createElement("button");
btn.className = `se-page-btn ${i === currentPage ? 'active' : ''}`;
btn.innerText = i;
btn.onclick = () => { currentPage = i; renderTable(); };
controls.appendChild(btn);
}
const nextBtn = document.createElement("button");
nextBtn.className = "se-page-btn";
nextBtn.innerText = "Next";
nextBtn.disabled = currentPage === totalPages;
nextBtn.onclick = () => { currentPage++; renderTable(); };
controls.appendChild(nextBtn);
}
window.seOpenPdfModal = function (url, title) {
document.getElementById("sePdfModalTitle").innerText = title;
document.getElementById("sePdfModalIframe").src = url;
document.getElementById("sePdfModal").style.display = "flex";
};
window.seClosePdfModal = function () {
document.getElementById("sePdfModal").style.display = "none";
document.getElementById("sePdfModalIframe").src = "";
};
document.addEventListener("DOMContentLoaded", fetchDokumenData);
})();