i have a problem on javascript reverse method when all the data to be sorted are equal.
here is my code:
var ascAgt = false;
function sortTableAgt() {
var tbl = document.getElementById("mytable").tBodies[0];
var store = [];
for (var i = 0, len = tbl.rows.length; i < len; i++) {
var row = tbl.rows[i];
var rowdatedata = row.cells[1].innerHTML;
store.push([rowdatedata, row]);
}
if (ascAgt) {
store.sort();
ascAgt = false;
} else {
store.sort();
store.reverse();
ascAgt = true;
}
for (var i = 0, len = store.length; i < len; i++) {
var idno = i + 1;
store[i][1].cells[0].innerHTML = idno.toString();
tbl.appendChild(store[i][1]);
} store = null;
}
sample data:
ID Name Date
1 XXXXX 2012/10/05
2 XXXXX 2012/03/16
3 XXXXX 2012/05/18
4 XXXXX 2012/05/18
as i sort the name part,what i want is that nothing happens because names are equal but when it comes to the reverse method it will just reversed the given data. am i missing something here? thank you in advance....
sortto work on an array containing arrays? Same withreverse.