3

I would disable order possibility to user after datatables is draw. I have a datatable, and I would order a data and remove possibility, for an user, to order data manually. How can I do it?

I used below code:

table = $('#tbl-1').DataTable({
            "info": false,
            "searching": true,
            "paging": false,
            "iDisplayLength": 25,
            "lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "Tutti"]],
            "language": {"url": "include/it_IT.txt"},
            "order": [[1,"desc"]],              
            //"ordering": false,
            //"orderFixed": {"pre": [ 1, "desc" ]},                             
             "fnInitComplete": function(oSettings, json) {
                    //alert( 'DataTables has finished its initialisation.' );
                    this.fnFilter("<?php echo $_POST['search'];?>");                        
                  },
            }).on('init.dt', function (e, settings, data) {
                wrappa(); //after custom function
            });
ArtOfWarfare
  • 20,617
  • 19
  • 137
  • 193
Valix85
  • 773
  • 1
  • 9
  • 20
  • [http://www.datatables.net/forums/discussion/7377/disable-all-sorting-after-init](http://www.datatables.net/forums/discussion/7377/disable-all-sorting-after-init) – markpsmith Dec 18 '14 at 11:10
  • I just see it but dosen't work on my site – Valix85 Dec 18 '14 at 14:49
  • **Addressing some potential confusion**. If you're looking to disable auto-sorting of your (e.g. server-side sorted) table after datatables init, but keep the sorting functionality enabled for intentional use, [see here](https://stackoverflow.com/a/4964423). If you want to disable the sorting completely, see below for an answer. – ᴍᴇʜᴏᴠ Jan 22 '19 at 08:31

2 Answers2

1

old post but still not handled by dt api. Removing the events won't work if wanting to temporarily disable sorting. Instead use jquery to add and later remove a class onto each th, and in this class specify "pointer-events: none".

Rick
  • 91
  • 1
  • 5
0

Due to the fact that the API does not have a way to do this, I would suggest the following approach

Declare your table at first

var table = $('#myTable').DataTable();

Re-Initialize your dataTable with to disable ordering

//Destroy your table before
table.destroy();
$('#myTable').dataTable( {
  "ordering": false
} );

reference: https://datatables.net/reference/option/ordering

zardilior
  • 2,810
  • 25
  • 30