question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Don't sort a column with same values

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:19 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
joequerycommented, Mar 17, 2016

I will be using tables for changing rather than sorting in the near future 💩

0reactions
joequerycommented, Jun 28, 2017

It took me a while but I cooked up a plugin/settings architecture and had this request implemented. See the should_redraw setting.

Thanks to everyone for the great discussion on this issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to prevent a column in a table from sorting
1. If you want to sort Column 1 and 3 ,you can put the column1 and 3 then select them to sort. Image...
Read more >
How to Sort in Excel Rows or Columns Avoid Sort Problems
Click Custom Order. In the Sort dialog box, select the Day column in the Sort By box. From the Order drop down, select...
Read more >
How to sort a column but keep intact rows in Excel?
In Excel, you can use the Sort function to sort a column and keep rows. 1. Select the column data you want to...
Read more >
Disable Sorting on every column except the first one
i'm currently using Datatables for a Custom system and i would like to disable Sort for every column but the ...
Read more >
In Excel, How to sort a column and keep respective values in ...
Highlight the column header (first row). In Excel 2007/2010, go to Data and click Filter. This applies a filter to each column that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found