I'm not entirely sure what my issue is here. I have the following sorting procedure that sorts a "table" (Not an actual HTML table):
function sortByName(tableBody) {
var projectList = [];
for (var i = 0; i < tableBody.length; i++) {
projectList.push(tableBody[i]);
}
console.log("about to enter");
//console.log(tableRows);
for(var i = 0; i < tableBody.length; i++){
var currentRow = tableBody[i];
if(currentRow.innerText !== null){
currentRow.style.display ="none";
}
}
projectList.sort(function(a,b){
var nameA = a.innerText.toUpperCase(); // ignore upper and lowercase
var nameB = b.innerText.toUpperCase(); // ignore upper and lowercase
if (nameA < nameB) {
return -1;
}
if (nameA > nameB) {
return 1;
}
// names must be equal
return 0;
});
console.log(projectList);
for(var q = 0; q < projectList.length; q++){
redisplayProjects(q, projectList);
}
}
function redisplayProjects(index, projectList){
console.log(projectList);
projectList[index].style.display = 'block';
}
Displaying to the console, the projectList is in fact sorted in the console but upon toggling the style.display back to 'block' the rows appear in the same order as they were pre-sorted. Am I missing something that anyone can help with?