Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery datatable disable sort in specific row

How to disable sorting in specific row/column in jquery datatable using a class?

here's my sample table;

    <table>
    <thead>
    <tr>
    <th class="sorting_disabled">Title1</th>
    <th class="">Title2</th>
    <th class="sorting_disabled">Title3</th>
    </tr>
    </thead>
    <tbody>
    <tr><td>Tag 1</td><td>Date 1</td><td>Date 2</td></tr>
    <tr><td>Tag 2</td><td>Date 2</td><td>Date 2</td></tr>
    <tr><td>Tag 3</td><td>Date 3</td><td>Date 3</td></tr>
    <tr><td>Tag 4</td><td>Date 4</td><td>Date 4</td></tr>
    <tr><td>Tag 5</td><td>Date 5</td><td>Date 5</td></tr>
....
    </tbody>
    </table>

script;

$('.sortable thead tr th.sorting_disabled').livequery(function() {
       $(this).removeClass('sorting');
       $(this).unbind('click');
    });

above code works but if I click to the next column who has a sorting its shows again an arrow. though its not clickable ;(

How can I disable the sorting by using a class and not using/redraw a table.

like image 902
mrrsb Avatar asked Jun 13 '12 08:06

mrrsb


2 Answers

You can disable the sorting using a class in definition. Just add this code to the datatable initialization:

// Disable sorting on the sorting_disabled class
"aoColumnDefs" : [ {
    "bSortable" : false,
    "aTargets" : [ "sorting_disabled" ]
} ]
like image 178
Paulo Fidalgo Avatar answered Sep 19 '22 14:09

Paulo Fidalgo


$('#example').dataTable( {
  "aoColumnDefs": [
      { 'bSortable': false, 'aTargets': [ 1 ] }
   ]});

That should do it..;)

like image 35
Alborz Avatar answered Sep 17 '22 14:09

Alborz