NARENDRA
NARENDRA

Reputation: 395

JQuery Datatable: How to disable sorting for specific <tr>

I want to disable sorting for first row of my table, that row looks like

<tr class="no-sort">
<td colspan="4"></td>
<td></td>
<td></td>
<td></td>
</tr>

Upvotes: 8

Views: 6558

Answers (1)

LeGEC
LeGEC

Reputation: 51790

Don't add this row to the data dipslayed.

Add code to your fnDrawCallback to add a row in your thead, or at the beginning of your tbody :

var opts = {};

opts.fnDrawCallback = function(){
    var mySpecialRow = '<tr><td>First</td><td>Second</td></tr>';

    $('#mytable thead').append(mySpecialRow);
    // or
    $('#mytable tbody').prepend(mySpecialRow);
}
$('#mytable').dataTable(opts);

Maybe I missed some details :

var $tr = $('#mytable tr.no-sort');
var mySpecialRow = $tr.html();
$tr.remove();

var opts = {};
opts.fnDrawCallback = function(){
    $('#mytable thead').append(mySpecialRow);
    // or
    $('#mytable tbody').prepend(mySpecialRow);
};

// add any other option you want
opts.sPaginationType = "full_numbers";

$('#mytable').dataTable(opts);    

Upvotes: 7

Related Questions