Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove sorting arrows in jQuery DataTables

I am using the jQuery DataTables plugin.

Is there a way I can get rid of the little arrows they display in the headers to indicate sorting options ? I would like to keep the functionality that by click on a header it sorts by this column, I just dont want to display the arrow icons as they change the layout of my column headers.

Firebug shows my headers as follows:

<th class="sorting" role="columnheader" tabindex="0" aria-controls="myTable" rowspan="1" colspan="1" style="width: 151px;" aria-label="Category: activate to sort column ascending">Category</th> 
like image 291
user2571510 Avatar asked Nov 25 '13 15:11

user2571510


People also ask

How to remove sorting in dataTable?

You can e.g. set style="display:none;" to the arrow element. You can set it programmatically using JavaScript or you can use CSS class.

How do I sort a specific column in a dataTable?

The existing answers are using legacy DataTables syntax. Versions 1.10+ should use the following syntax: $('table'). dataTable({ "pageLength": -1, //display all records "order": [[ 0, "desc" ]] // Sort by first column descending });


2 Answers

The icons is defined as background : url(..) on the CSS classes. Disable them by :

.sorting, .sorting_asc, .sorting_desc {     background : none; } 

see jsfiddle -> http://jsfiddle.net/5V2Dx/ Note : This solution is for datatables 1.9.x!!


Update. When using datatables 1.10.x, the CSS for resetting the header icons is a little bit different :

table.dataTable thead .sorting,  table.dataTable thead .sorting_asc,  table.dataTable thead .sorting_desc {     background : none; } 

see -> http://jsfiddle.net/kqpv3ub9/ (updated demo is using dataTables 1.10.11)

like image 85
davidkonrad Avatar answered Sep 26 '22 04:09

davidkonrad


None of the presented solutions worked for me. But I have just found this one;

.dataTable > thead > tr > th[class*="sort"]:before, .dataTable > thead > tr > th[class*="sort"]:after {     content: "" !important; } 

PS.: DataTables version "datatables": "~1.10.2"

like image 44
Renato Gama Avatar answered Sep 22 '22 04:09

Renato Gama