How sort table using a link outside the table ?

How sort table using a link outside the table ?

svetlan@svetlan@ Posts: 3Questions: 1Answers: 0

I need your help to solve such a problem. I need to sort my table using a link outside the table, not headers of the table (<th>). And headers of the table must be unsortable (disable sort function). How can I do this? Maybe, someone has faced with such task. Thank you,

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,791Questions: 1Answers: 10,513 Site admin
    Answer ✓

    Use the order() method to order the table via the API. Use columns.orderable to disable user ordering of the column headers.

    Allan

  • svetlan@svetlan@ Posts: 3Questions: 1Answers: 0
    edited April 2016

    Thank you! It works)
    May I ask you one more question?
    How can I diasable default sorting when loading my page?
    Now I have my table sorted at once by 1 column, but I need begin sorting only when user click the link.

    My code:

    var table = $('.datatable').DataTable({
    "paging": false,
    "searching": false,
    "info": false,
    "columnDefs": [
    { "orderable": false, "targets": [0, 1, 2, 3]}
    ]
    });

        $("#trigger-link1").click(function() { 
            if($(this).hasClass("up")){
                table.order([0, 'asc']).draw();
                $(this).addClass("down").removeClass("up");
                return false; 
            } else {
                table.order([0, 'desc']).draw();
                $(this).addClass("up").removeClass("down");
                return false; 
            }
        });
    

    });

  • svetlan@svetlan@ Posts: 3Questions: 1Answers: 0

    Oh, I'm sorry. I find it by myself))
    Just added

    "order": []

This discussion has been closed.