Remplir une table en utilisant un objet javascript
salam alikoum,
je suis nouveau dans ce Forum très respectueux, j'ai fais un simple exemple pour remplir une table html en parcourant un objet rempli des données, je n'ai pas compris pourquoi ça ne marche pas si quelqu'un l'a déjà fait et peux m'aider ça sera la bienvenue
le code de la page est le suivant :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| <head>
<title>Example</title>
</head>
<body>
<table id="table">
<thead>
<tr>
<th>Matricule</th>
<th>Date Exploit</th>
<th>Num RUB</th>
<th>Lib RUB</th>
<th>Date Début</th>
<th>Date Fin</th>
<th>Montant Mois</th>
<th>Taux</th>
<th>Base</th>
</tr>
</thead>
<tbody id="tableBody">
<!-- Datas will be uploaded here -->
</tbody>
</table>
<script>
document.addEventListener('DOMContentLoaded', function () {
async function loadRUBData(limit, offset, month, year) {
// Hardcoded data for testing
const rubData = [{ matricule: '123', dateexpl: '2023-09-01', numrub: '100', librub: 'Test', datedeb: '2023-09-01', datefin: '2023-09-30', montantmois: 1000, taux: 5, base: 500 }];
const tableBody = document.querySelector("#tableBody");
tableBody.innerHTML = "";
for (const entry of rubData) {
const row = document.createElement("tr");
row.innerHTML = `
<td>${entry.matricule}</td>
<td>${entry.dateexpl}</td>
<td>${entry.numrub}</td>
<td>${entry.librub}</td>
<td>${entry.datedeb}</td>
<td>${entry.datefin}</td>
<td>${entry.montantmois}</td>
<td>${entry.taux}</td>
<td>${entry.base}</td>`;
tableBody.appendChild(row);
}
}
}
const limit = 10//${request.getAttribute("limit")};
const offset = 0//${request.getAttribute("offset")};
const month = '09'//${request.getAttribute("month")};
const year = '2023'//${request.getAttribute("year")};
loadRUBData(limit, offset, month, year);
});
</script>
</body>
</html> |
merci beaucoup.