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?

KyopaxaKyopaxa Posts: 2Questions: 0Answers: 0
edited August 2013 in DataTables 1.9
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.

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    There isn't currently a aaSortingFixed post-fix option - aaSortingFixed is a pre-fix option as you have found, so I wouldn't use aaSortingFixed at all in this case.

    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
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    I've just added the ability to add post-fix ordering to DataTables 1.10: https://github.com/DataTables/DataTablesSrc/commit/953038e :-)

    Allan
This discussion has been closed.