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
vince2y ago
Does tbody tr work? Inside the function
kingtigerknight
I forgot the add the tbody! WHOOPS XD Thanks 🙂
vince
vince2y ago
Np haha