How to always sort all columns by a last column, giving preference to existing sort options?
How to always sort all columns by a last column, giving preference to existing sort options?
Kyopaxa
Posts: 2Questions: 0Answers: 0
Hi,
I have a table that groups rows by different columns selected by the user. To perform the grouping it uses aaSortingFixed for the column being grouped at that moment.
Now I am in need to always sort by a last column Z. This sort by Z should be applied always in the last position, giving preference to any other sort options currently applied by the user.
I tried using aDataSort for every column, specifying Z as the last column to sort with. The problem is that this approach doesn't work as intended when aaSortingFixed points to a column that uses aDataSort. What happens is that aaSortingFixed will be applied first and will use aDataSort to also sort by Z, then the rest of the sort options will be applied AFTER the sorting by Z.
Here is a fiddle example of the problem: http://jsfiddle.net/HNTez/2/
Is there any option like aaSortingFixed but that applies the fixed sort at the end instead of at the beginning? If not, wouldn't it be a nice feature to have? It could be called aaSortingFixedLast for example.
I have a table that groups rows by different columns selected by the user. To perform the grouping it uses aaSortingFixed for the column being grouped at that moment.
Now I am in need to always sort by a last column Z. This sort by Z should be applied always in the last position, giving preference to any other sort options currently applied by the user.
I tried using aDataSort for every column, specifying Z as the last column to sort with. The problem is that this approach doesn't work as intended when aaSortingFixed points to a column that uses aDataSort. What happens is that aaSortingFixed will be applied first and will use aDataSort to also sort by Z, then the rest of the sort options will be applied AFTER the sorting by Z.
Here is a fiddle example of the problem: http://jsfiddle.net/HNTez/2/
Is there any option like aaSortingFixed but that applies the fixed sort at the end instead of at the beginning? If not, wouldn't it be a nice feature to have? It could be called aaSortingFixedLast for example.
This discussion has been closed.
Replies
In your example, without aaSortingFixed, clicking on column index 0 or 4 will cause sorting by that column and then column index 1. It isn't shown visually, but the sorting is applied that way.
The other option is to modify DataTables to have a post-fix sorting option (not a bad idea for a future enhancement).
Allan
Allan