Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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>
like image 744
NARENDRA Avatar asked Mar 14 '13 11:03

NARENDRA


1 Answers

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);    
like image 150
LeGEC Avatar answered Sep 30 '22 21:09

LeGEC