fixed sort column, but as second sort criteria

fixed sort column, but as second sort criteria

jamovjamov Posts: 5Questions: 0Answers: 0
edited July 2012 in DataTables 1.8
I need a fixed sort column, but instead of the fixed sorted column being the first sort criteria, I need it to be the second.
So:
A 3
A 2
A 4
B 5
B 1
B 6

if column 1 is header clicked , and I also want column 2 to be sorted as the second sort.
I sould yield
A 2
A 3
A 4
B 1
B 5
B 6

rather than
B 1
A 2
A 3
A 4
B 5
B 6
if the second column was first sort criteria in the fixedcolumn option.


I've also tried using aoColumns and aoColumnDefs. I seem to be able to make columns work together this way when using an html filled table, but when using an ajax retrieved json array to fill the data, those options seem to get ignored.

I have also tried fnSort...which works beautifully when called, but I can't seem to make it fire when a particular header is clicked, the listener seems to be for other elements in the dom.

I am using fixedheader to float the header, so perhaps that has added some complexity.

Any help is appreciated.

Replies

  • allanallan Posts: 63,489Questions: 1Answers: 10,470 Site admin
    > if column 1 is header clicked , and I also want column 2 to be sorted as the second sort.

    The aDataSort property is what to use for this - it will let you specify the columns to do a multi0column sort on in the initialisation for each column. Using FixedHeader shouldn't make any different to using this parameter :-)

    Allan
  • jamovjamov Posts: 5Questions: 0Answers: 0
    edited July 2012
    I have tried aDataSort with both aoColumnDefs and aoColumns.
    These seem to work if I have statically defined data.
    However, my table is pulling in the data via sAjaxSource.

    [code]
    oTable = $('#mytable').dataTable( {
    "bJQueryUI": true,
    "sAjaxSource": ,
    "bScrollInfinite": true,
    "bPaginate": false,
    "sDom": '<"H"T>rt<"F"lip>',
    "bProcessing": true,
    "bDeferRender": true,
    "aoColumnDefs": [
    { "aDataSort": [ 0, 2 ], "aTargets": [0]},
    { "aDataSort": [ 1, 2 ], "aTargets": [1] },
    { "aDataSort": [ 2, 0 ], "aTargets": [2] },
    { "aDataSort": [ 3, 2 ], "aTargets": [3] },
    { "aDataSort": [ 4, 2 ], "aTargets": [4] },
    { "aDataSort": [ 5, 2 ], "aTargets": [5] },
    { "aDataSort": [ 6, 2 ], "aTargets": [6] },
    { "aDataSort": [ 7, 2 ], "aTargets": [7] },
    { "aDataSort": [ 8, 2 ], "aTargets": [8] },
    { "aDataSort": [ 9, 2 ], "aTargets": [9] },
    { "aDataSort": [ 10, 2 ], "aTargets": [10] }
    ],
    "oTableTools": {
    "aButtons": buttons //this array is dynamically build and buttons work
    }
    } );
    [/code]

    datatables displays correctly with above code, it just doesn't seem to group the sorting when I click the headers. I must be missing something. It instead just sorts on the clicked header.

    When using aoColumns instead, if I put the wrong number of columns in, it throws a warning so I know the columns section is being looked at....but with the correct number of columns specified, no group sorting when headers are clicked.
This discussion has been closed.