When using array sort, how to ignore the table header?

Here is what I have tried
function sortTable(headerClicked, column) {
tableContainerRows = tableContainer.querySelectorAll('tr');

const rowsDuplicate = Array.from(tableContainerRows);

rowsDuplicate.sort(function (rowA, rowB) {
console.log(rowA, rowB);

// Get the content of cells
const cellA = rowA.querySelectorAll('td')[column].innerHTML;
console.log(cellA);
const cellB = rowB.querySelectorAll('td')[column].innerHTML;
console.log(cellB);
})
}
function sortTable(headerClicked, column) {
tableContainerRows = tableContainer.querySelectorAll('tr');

const rowsDuplicate = Array.from(tableContainerRows);

rowsDuplicate.sort(function (rowA, rowB) {
console.log(rowA, rowB);

// Get the content of cells
const cellA = rowA.querySelectorAll('td')[column].innerHTML;
console.log(cellA);
const cellB = rowB.querySelectorAll('td')[column].innerHTML;
console.log(cellB);
})
}
The only error I have is that it gets the 1st row which is the headers and that becomes a problem
3 Replies
vince
vince•3y ago
Does tbody tr work? Inside the function
kingtigerknight
kingtigerknightOP•3y ago
I forgot the add the tbody! WHOOPS XD Thanks 🙂
vince
vince•3y ago
Np haha
Want results from more Discord servers?
Add your server