Initial sorting with ordering is false

Initial sorting with ordering is false

Murphy013Murphy013 Posts: 15Questions: 5Answers: 1

I wanna define an initial sorting for a table where the user have no possibility to change sorting.
I tried

        var dtable = $('#tableData').DataTable({
            ordering: false,
            order: [ [ 2, 'asc' ],[ 0, 'asc' ] ],

and of course there is no sorting because ordering is switched off.

I also tried to disable sorting with

                { visible: true ,
                    orderable: false,

but the first column still shows a sort button.

Is there a way to do an initial sorting without the possibility for the user to change oredering?

regards

This question has accepted answers - jump to:

Answers

  • kthorngrenkthorngren Posts: 21,336Questions: 26Answers: 4,951
    Answer ✓

    but the first column still shows a sort button.

    Not sure what the code snippet you posted applies to. Are you using columnDefs.targets set to _all?

    The sort buttons will always show if the column is being sorted. As you show the columns.orderable is the option to use to turn off the user's ability to sort the column(s). Here is an example:
    http://live.datatables.net/qepirahi/1/edit

    Kevin

  • Murphy013Murphy013 Posts: 15Questions: 5Answers: 1

    Hi Kevin,

    thanks for your example. I still see the sort buttons for the 2 columns which are used for initiail sorting. As I understood they are shown because they are used for initial sorting.
    Is it possible to hide them that the user will not see them? In my case I have a filter table and a datatable which doesn't have colheaders. So it looks ugly.
    Have a look here: http://live.datatables.net/bepehuku/1/edit

    Regards

  • kthorngrenkthorngren Posts: 21,336Questions: 26Answers: 4,951
    edited April 2022 Answer ✓

    Generally you can make changes to Datatables styling by inspecting the component then overriding the CSS. The sorting image looks like this:

    table.dataTable thead .sorting_asc {
        background-image: url(/DataTables-1.10.18/images/sort_asc.png);
    }
    

    Add this CSS to hide the image:

    table.dataTable thead .sorting_asc {
      display: none;
    }
    

    http://live.datatables.net/gefuhaki/1/edit

    Kevin

Sign In or Register to comment.