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
            });
3
  • http://www.datatables.net/forums/discussion/7377/disable-all-sorting-after-init Commented Dec 18, 2014 at 11:10
  • I just see it but dosen't work on my site Commented Dec 18, 2014 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. If you want to disable the sorting completely, see below for an answer. Commented Jan 22, 2019 at 8:31

2 Answers 2

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".

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

Comments

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

3 Comments

this isn't correct because i need to ordering first time, and only after ordering i must disable..
if you set ordering : false on the column OP wants to prevent the user to be able to sort on, he will loose his own ordering, eg "order": [[1,"desc"]], as well.
This will disable the ordering completely

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.