codice:
// Dichiarazione e inizializzazione delle variabili per la paginazione
const recordsPerPage = 5; // Numero di record per pagina
let currentPage = 1; // Pagina corrente iniziale
// Funzione per recuperare i dati della pagina dal server
function fetchPage(page, search = "") {
const params = new URLSearchParams();
params.append("page", page);
params.append("search", search); // Aggiunto per supportare la ricerca
params.append("recordsPerPage", recordsPerPage);
//inizializzazione tabella dipendenti e caricamento dati dinamici in tabella
fetch("../php/dipend.php", {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
body: params,
})
.then((response) => response.json())
.then((data) => {
const tbody = document
.getElementById("tableDipendenti")
.getElementsByTagName("tbody")[0];
tbody.innerHTML = ""; // Pulisci la tbody prima di aggiungere nuove righe
data.data.forEach((row) => {
const tr = document.createElement("tr");
tr.setAttribute('data-id', row.iddip); // Assicurati che ogni riga abbia un data-id
tr.innerHTML = `
<td class="icon-cell"><i class="fa fa-arrow-circle-o-right fa-2x" aria-hidden="true" onclick="toggleBadgeDetails(event, this.parentElement.parentElement.getAttribute('data-id'))"></i></td>
<td class="dip-data-cell">${row.matr}</td>
<td class="dip-data-cell">${row.cognome}</td>
<td class="dip-data-cell">${row.nome}</td>
<td class="dip-data-cell">${row.nascita}</td>
<td class="dip-data-cell">${row.matrcomune}</td>
<td class="dip-data-cell">${row.assunzione}</td>
<td class="dip-data-cell">${row.iniznomin}</td>
<td class="dip-data-cell"><img src="${row.foto}" style="height:50px; width:50px;"></td>
<td class="dip-data-cell">${row.stato}</td>
<td class="hidden-id">${row.totbadge}</td>
`;
tr.addEventListener("click", function () {
const idDipendente = row.iddip;
// Mostra l'ID del dipendente in un alert
alert("ID del dipendente cliccato: " + idDipendente);
});
tbody.appendChild(tr);
});
updatePagination(data.totalPages, currentPage);
})
.catch((error) => {
console.error("Errore di rete:", error);
});
}