Skip to content

Commit

Permalink
Update empty message display logic
Browse files Browse the repository at this point in the history
  • Loading branch information
navinAce committed Sep 26, 2024
1 parent 0a28fd7 commit eac1bdc
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
7 changes: 6 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@ <h1>Chemical Supplies</h1>
</tr>
</thead>
<tbody id="tableData">
<tbody>
<tr id="emptyMessageRow">
<td colspan="10" style="text-align: center; color: #888;">
Add chemicals data to see them listed here.
</td>
</tr>
</tbody>
</table>

<!-- Add new chemical form -->
Expand Down
21 changes: 19 additions & 2 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ function addItemForm() {
function addNewChemical(newChemical) {

chemicals.push(newChemical);
updateEmptyMessage();
appendChemicalToTable(newChemical,chemicals.length - 1);
}

Expand Down Expand Up @@ -199,13 +200,19 @@ function deleteSelectedChemicals() {
tableBody.deleteRow(index);
});
rebuildTable();
updateEmptyMessage();
}

// Rebuild the table to ensure the IDs and checkboxes remain accurate

function rebuildTable() {
const tableBody = document.querySelector("#tableData");
tableBody.innerHTML = "";
tableBody.innerHTML = `
<tr id="emptyMessageRow" style="display: none;">
<td colspan="10" style="text-align: center; color: #888;">
Add chemicals data to see them listed here.
</td>
</tr>`;

chemicals.forEach((chemical, index) => {
appendChemicalToTable(chemical, index);
Expand Down Expand Up @@ -255,4 +262,14 @@ function sortChemicalsByName(isAscending) {

document.querySelector("#refreshAll").addEventListener("click", function () {
location.reload();
})
})

// empty message

function updateEmptyMessage() {
const emptyMessageRow = document.getElementById('emptyMessageRow');

if (emptyMessageRow) {
emptyMessageRow.style.display = chemicals.length === 0 ? 'table-row' : 'none';
}
}
14 changes: 13 additions & 1 deletion styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ h1{

.table-wrapper{
margin: 10px 70px 70px;

}

.fl-table {
Expand Down Expand Up @@ -68,6 +67,7 @@ h1{
.fl-table {
display: block;
width: 100%;
min-height: 600px;
}
h1{
font-size: 23px;
Expand Down Expand Up @@ -213,3 +213,15 @@ th:nth-child(3):hover::after {
opacity: 1;
}

/* Styles for the empty message row */
#emptyMessageRow {
display: none;
background-color: #f9f9f9;
color: #888;
font-size: 16px;
text-align: center;
height: 50px;
}



0 comments on commit eac1bdc

Please sign in to comment.