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

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

<tr class="no-sort"> <td colspan="4"></td> <td></td> <td></td> <td></td> </tr> 
+7
source share
1 answer

Do not add this row to data that has been deferred.

Add the code to your fnDrawCallback to add a line to 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); 

I might have 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); 
+6
source

All Articles