Syntax for multi-column sorting

Syntax for multi-column sorting

brianKbrianK Posts: 9Questions: 5Answers: 0
edited May 2014 in DataTables 1.10

When a user clicks on column 1 (the second column, they are 0-based right?), I want to sort on 1, and then if they are the same, soft on column 4. Is this the proper syntax?

    $(document).ready(function() {
            var table = $('#example').DataTable( 
            {
                scrollY:        "300px",
                scrollX:        true,
                scrollCollapse: true,
                paging:         false
            },
            {
                "columnDefs": [
                    { "orderData": 0,       "targets": 0 },
                    { "orderData": [1, 4],  "targets": 1 },
              ]
            } 
        );

        new $.fn.dataTable.FixedColumns( table, 
            {
                "leftColumns": 1        
            });

    } );

Answers

  • allanallan Posts: 63,494Questions: 1Answers: 10,470 Site admin

    they are 0-based right?

    Yes

    Is this the proper syntax?

    Not quite, Only pass one object into DataTables:

    $(document).ready(function() {
            var table = $('#example').DataTable(
            {
                scrollY:        "300px",
                scrollX:        true,
                scrollCollapse: true,
                paging:         false,
                "columnDefs": [
                    { "orderData": 0,       "targets": 0 },
                    { "orderData": [1, 4],  "targets": 1 },
              ]
            }
        );
     
        new $.fn.dataTable.FixedColumns( table, {
                "leftColumns": 1       
            });
    } );
    

    Allan

  • brianKbrianK Posts: 9Questions: 5Answers: 0

    Thanks! I'm just getting started with DataTables.

This discussion has been closed.