Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable Ordering Columns after initialization (init complete) in datatables

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
            });
like image 394
Valix85 Avatar asked Apr 15 '26 08:04

Valix85


1 Answers

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

like image 86
Rick Avatar answered Apr 17 '26 20:04

Rick