1

I am using datatable API. Here, I want to hide sorting arrows for some specific columns. How do I do that ?

I tried this code but didn't work.

$('#example').dataTable( {
  "columnDefs": [
    { "orderable": false, "targets": 0 }
  ]
});
2
  • change 'datatable' tag to 'jquery-datatables' please. Commented Nov 29, 2016 at 17:11
  • I updated the answer to correct the tags. Also note that datatables tag is remapped to jquery-datatables tag (link). Commented Nov 30, 2016 at 0:50

1 Answer 1

4

If you want to target a specific column, multiple columns, or all columns, use the aTargets property instead your "targets". The aTargets property is an array to target one of your columns and it can be:

  • aTargets : [0] - first column from the left
  • aTargets : [1] - second column, etc...
  • aTargets: ['_all'] - select all columns

So if you want to hide sorting arrow for let's say first column, use this code:

$(document).ready(function() {
    $('#example').DataTable( {
        aoColumnDefs : [ {
           orderable : false, aTargets : [0]        
        }],
        order: [] 
    } );
} );

During initialization in example we don't want to apply ordering, so we set order property empty:

order: [] 

I choose one table from datatables examples and put all this in working example: jsFiddle

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

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.