order: [[ 1, "desc" ]] not working

order: [[ 1, "desc" ]] not working

mitch2kmitch2k Posts: 3Questions: 2Answers: 0

Hi,

I'm trying to change the default ordening for my table like this:

// Basic ColVis example
$('.datatable-colvis-basic').DataTable({
    colVis: {
        buttonText: "<i class='icon-three-bars'></i> <span class='caret'></span>",
        align: "right",
        overlayFade: 200,
order: [[ 1, "desc" ]],
        showAll: "Show all",
        showNone: "Hide all"
    }
});

I guess the "order: [[ 1, "desc" ]]," should force the table to sort on that column, but it doesn't. Am I missing something?

Thanks

This question has an accepted answers - jump to answer

Answers

  • SamuelNZSamuelNZ Posts: 62Questions: 5Answers: 2
    edited November 2015

    Try:

    // Basic ColVis example
    $('.datatable-colvis-basic').DataTable({
        colVis: {
            buttonText: "<i class='icon-three-bars'></i> <span class='caret'></span>",
            align: "right",
            overlayFade: 200,
            order: 'alpha',
            showAll: "Show all",
            showNone: "Hide all"
        }
    });
    

    Additionally, You should be using the Buttons extension now as Colvis is retired.

  • SamuelNZSamuelNZ Posts: 62Questions: 5Answers: 2
    edited November 2015

    I'm not sure if you can call aaSorting from within Colvis, So try this if the above doesn't work:

    // Basic ColVis example
    $('.datatable-colvis-basic').DataTable({
        colVis: {
            buttonText: "<i class='icon-three-bars'></i> <span class='caret'></span>",
            align: "right",
            overlayFade: 200,
            showAll: "Show all",
            showNone: "Hide all"
        },
        aaSorting: [[1,'desc']]
    });
    
  • allanallan Posts: 63,760Questions: 1Answers: 10,510 Site admin
    Answer ✓

    Yes - the issue is that order is not a property of the colVis options. It is a top level option:

    // Basic ColVis example
    $('.datatable-colvis-basic').DataTable({
        colVis: {
            buttonText: "<i class='icon-three-bars'></i> <span class='caret'></span>",
            align: "right",
            overlayFade: 200,
            showAll: "Show all",
            showNone: "Hide all"
        },
        order: [[ 1, "desc" ]]
    });
    

    See the order reference documentation for details and further examples.

    Allan

  • mitch2kmitch2k Posts: 3Questions: 2Answers: 0

    Thanks Allan, that was indeed the issue.

This discussion has been closed.