Sorting hidden column as secondary sorting column

Sorting hidden column as secondary sorting column

fredriofredrio Posts: 2Questions: 0Answers: 0
edited September 2011 in General
I wish to do secondary sort on a specific hidden column (or more) when I choose to sort a visible column. Does anyone know how this can be done?

Replies

  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    You'd have to catch the column click and manually call fnSort with both columns:
    [code]
    var oTable;

    $(document).ready(function() {
    oTable = $('#example').dataTable();

    /* Sort immediately with columns 0 and 1 */
    oTable.fnSort( [ [0,'asc'], [1,'asc'] ] );
    } );
    [/code]


    ---------------
    DT allows you to associate a different column with a given column, but this only works with a single column, unfortunately (as far as I know)

    http://www.datatables.net/ref#iDataSort

    maybe Allan can expand iDataSort to allow an object array like fnSort? You're at least the 2nd person to ask this question in the past month. And it would be easier to specify iDataSort than to catch the column header click.
  • fredriofredrio Posts: 2Questions: 0Answers: 0
    Thanks for your response. I am able to solve my problem by using only one hidden column generated on the server side. However, your suggestion to adapt iDataSort to take an array of columns to support multi-column sorting would be a nice addition to this great API.
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Yup - sounds like a good idea. I've noted it down for future enhancements.

    Allan
This discussion has been closed.