4

I've used this table. I need my first row of tbody(which displays average number of the columns) should not be sorted, I mean that row should in top always(below thead) like this: . How can I do this? I search solution on google and mostly I find put that row on the thead or something like that. But, if I try to put that row on that place, it seems so complex to me. So, is there any way put a class on the row and disabling sortng on that classed row? like: <tr class="average no-sort"></tr>

Fiddle

4 Answers 4

4

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

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);

    }                   
});
Sign up to request clarification or add additional context in comments.

Comments

0

Also looking for a solution for this. It's easy to do by modifying the dom after the table has initiated, but that breaks all of the responsive features.

Need a way to keep rows at the top of the table after sorting and filtering has been done.

Comments

0

I create the second tbody in my table and just move all rows I need to persist in that another tbody like so:

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();
        }
    });
}

Comments

0
  1. Remove the row which has to remain unsorted from body of the table.
  2. Include the row to be added in the footer of the table if it is the last row.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.