How to disable sorting from some specific rows in DataTables

I used this table . I want my first line of tbody(which represents the average number of columns) must not be sorted, I mean that the line should always be at the top ( below thead) as follows: LV9Ma9R.png. How can i do this? I am looking for a solution on google, and basically I find that this line is on theador something like that. But, if I try to put this line in this place, it seems to me that it is so difficult. So, is there a way to put a class in a string and disable sorting in that cool string? eg:<tr class="average no-sort"></tr>

Fiddle

+4
source share
4 answers

I had the same problem, in my case I solved it like this:

var $tr = $('#yourTable tr.no-sort'); //get the reference of row with the class no-sort
var mySpecialRow = $tr.prop('outerHTML'); //get html code of tr
$tr.remove(); //remove row of table

$('#yourTable').dataTable({
    "fnDrawCallback": function(){
        //add the row with 'prepend' method: in the first children of TBODY
        $('#yourTable tbody').prepend(mySpecialRow);

    }                   
});
+1
source

I create a second tbodyin my table and simply move all the rows that I need to save in the following tbody, for example:

initComplete: function() {
    var self = this;

    var api = this.api();
    api.rows().eq(0).each(function(index) {
        var row = api.row(index);
        if (row.data()...) { // condition here
            var $row_to_persist = $(row.node());
            var $clone = $row_to_persist.clone();

            $(self).find('tbody:last').append($clone);

            $total_row.remove();
            row.remove();
            api.draw();
        }
    });
}
0
source

. , dom , , .

, .

0
  1. , .
  2. , , .
0

Source: https://habr.com/ru/post/1545727/


All Articles