Skip to content

Commit

Permalink
Fix table null error
Browse files Browse the repository at this point in the history
  • Loading branch information
khleomix committed May 23, 2024
1 parent 1052514 commit 6f1ab28
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions assets/js/global/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,27 @@ document.addEventListener('DOMContentLoaded', function () {
// Get the header row of each table
const headerRow = table.rows[0];

// Loop through each cell of the header row
Array.from(headerRow.cells).forEach(function (cell, index) {
const label = cell.textContent.trim();
if (headerRow) {
// Check if headerRow is defined
// Loop through each cell of the header row
Array.from(headerRow.cells).forEach(function (cell, index) {
const label = cell.textContent.trim();

// Loop through each row (excluding the header row)
for (let i = 1; i < table.rows.length; i++) {
// Get the cell in the same column from the current row
const cellInColumn = table.rows[i].cells[index];

// Set the data-label attribute with the content of the header cell
cellInColumn.setAttribute('data-label', label);
}
});
// Loop through each row (excluding the header row)
for (let i = 1; i < table.rows.length; i++) {
const currentRow = table.rows[i];
if (currentRow) {
// Check if currentRow is defined
// Get the cell in the same column from the current row
const cellInColumn = currentRow.cells[index];
if (cellInColumn) {
// Check if cellInColumn is defined
// Set the data-label attribute with the content of the header cell
cellInColumn.setAttribute('data-label', label);
}
}
}
});
}
});
});

0 comments on commit 6f1ab28

Please sign in to comment.