How can I remove ALL sort arrows from ALL columns?

How can I remove ALL sort arrows from ALL columns?

ckennedy65ckennedy65 Posts: 1Questions: 1Answers: 0

I am trying to remove all of the sort arrows from the column headers when 'orderable' is set to false.

I included the following code in my datatable definition but an arrow continues to appear on the first column. I am not allowing sorting on any column, rather I'm using filtering and I don't want the sort arrows showing up at all.

columnDefs: [{
"orderable": false,
"targets": '_all'
}

Answers

  • kthorngrenkthorngren Posts: 17,689Questions: 25Answers: 4,197

    The columns.orderable only affects the users ability to order columns. As stated in the docs the order option and order() API can affect the order. Thus the arrows still show. You can turn off all ordering with order like order: []. Datatables will then show the table in the order of the data received.

    Kevin

  • kthorngrenkthorngren Posts: 17,689Questions: 25Answers: 4,197

    You could inspect the sorting arrows and override the CSS settings. For example the default Datatables CSS to show the sorting icons is this:

    table.dataTable thead .sorting_asc {
        background-image: url(../images/sort_asc.png) !important;
    }
    
    table.dataTable thead .sorting_desc {
        background-image: url(../images/sort_desc.png) !important;
    }
    
    table.dataTable thead .sorting {
        background-image: url(../images/sort_both.png);
    }
    

    You can change the background to something else if you wish.

    Kevin

  • leighJaneleighJane Posts: 13Questions: 2Answers: 0

    This needs a better solution. Kevin's solution to edit the css didn't work for me because I couldn't even find the snippets he pasted above. The only reference to table.dataTable thead was in css/plugins/datatables/dataTables.bootstrap.min.css and I removed the entire css from the page and it didn't change a thing

  • kthorngrenkthorngren Posts: 17,689Questions: 25Answers: 4,197

    @leighJane The above CSS likely only works with the default Datatables styling. Depending on your goals you could simply set ordering to false. This will turn off all table ordering and the arrows won't show. If this doesn't help then please provide more information about your requirements.

    Kevin

  • leighJaneleighJane Posts: 13Questions: 2Answers: 0

    Perfect!! That worked for me. Thanks Kevin

  • awariatawariat Posts: 4Questions: 2Answers: 0

    I removed this way in my css:

    table.dataTable>thead .sorting::before,
     table.dataTable>thead .sorting_asc::before,
     table.dataTable>thead .sorting_desc::before,
     table.dataTable>thead .sorting_asc_disabled::before,
     table.dataTable>thead .sorting_desc_disabled::before {
        right: 0;
        content: "";
    }
    
     table.dataTable>thead .sorting::after,
     table.dataTable>thead .sorting_asc::after,
     table.dataTable>thead .sorting_desc::after,
     table.dataTable>thead .sorting_asc_disabled::after,
     table.dataTable>thead .sorting_desc_disabled::after {
        right: 0;
        content: "";
    }
    
     table.dataTable>thead>tr>th:not(.sorting_disabled),
     table.dataTable>thead>tr>td:not(.sorting_disabled) {
        padding-right: 4px;
        padding-left: 4px;
    }
    
     table.dataTable>thead>tr>th,
     table.dataTable>thead>tr>td {
        padding-right: 4px;
        padding-left: 4px;
    }
    
Sign In or Register to comment.