How to order my last column ?

How to order my last column ?

AlexolAlexol Posts: 11Questions: 4Answers: 0

Hello,

My table includes several columns that are added as they are added, so they can be extended.
The last column contains a total of these columns and I want to sort on this last column only

"order": [[-1,'desc']] doesn't work...?

Thank you.

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599
    Answer ✓

    Hi @Alexol ,

    Yep, order expects the column index. You can calculate it before you initialise the table and pass in a variable.

    Cheers,

    Colin

  • AlexolAlexol Posts: 11Questions: 4Answers: 0
    edited September 2019

    Thank you, I thought there would be direct feature but this will be enough

    $(document).ready( function () {
        var indexLastColumn = $("#table-classement").find('tr')[0].cells.length-1;
        $('#table-classement').DataTable({
            "order":[[indexLastColumn,'desc']]
        });
    });
    
This discussion has been closed.