Stupid-Table-Plugin: Don't sort a column with same values
for a column whom all its values are the same, do not bother sorting. Touching the DOM for no reason costs in performance and if better to avoid.
Here’s a quick idea how to check if all columns values are the same:
var table = document.querySelector('table'),
rowsCount = table.rows.length,
values = {};
// lets say a user is sorting the first column
// skip the first tr which only has "th"..
while( rowsCount-- > 1){
values[ table.rows[rowsCount].children[0].textContent ] = 1;
}
// same value if the object has less than 2 keys
if( Object.keys(values).length < 2 )
return; // do not sort
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 19 (9 by maintainers)
I will be using tables for changing rather than sorting in the near future 💩