I am using the following code to sort the columns in the table using the header row as a trigger.
var tr = d3.selectAll("tbody tr");
d3.selectAll("thead th").data(forsort).on("click", function(k) {
tr.sort(function(a,b){
return a[k] - b[k]; });
});
The problem is, there are quite a few cells with same values. When I click to sort the table the first time, it does what is expected. But, if i click it again, it will rearrange those rows which have the same valued cell (from the column being used to sort) in them.
I was wondering if there was anyway to check if the column is already sorted and if true then not allow repeated sorting.
Any alternate solutions are also welcome.
Thanks!
Here’s an idea: