Removing Sort Order for Columns with Bootstrap

Removing Sort Order for Columns with Bootstrap

upstatewebupstateweb Posts: 4Questions: 2Answers: 0

The first and last column need not have a sort order. I have been perusing the forums and examples for days and have tried everything. Can anyone help. The first page of the script works to create the buttons, but the second part will not assign which columns can be sorted and which cannot:

Script:

    $(document).ready(function() {
        var table = $('#example').DataTable();
        var tt = new $.fn.dataTable.TableTools( table , {
            sSwfPath: 'bootstrap/datatables/extensions/TableTools/swf/copy_csv_xls_pdf.swf',
            aButtons: [ 'copy', 'xls', 'pdf' ],
        });
        $( tt.fnContainer() ).insertBefore('div.dataTables_wrapper');
    } );
    $(document).ready(function() {
        var table = $('#example').DataTable( table, {
                     columnDef: {
                     targets: [ 1,5 ],
                     visible: true,
                     orderable: false
                    },
        columnDef: {
                    targets: [ 2,3,4 ],
                    visible: true,
                    orderable: true
        }
               });
    } );

This is my first attempt at using DataTables so I am sure I have something wrong. The test page is at http://www.upstateweb.com/webmgr/test.cfm.

Thank you in advance for your help,

David G. Moore, Jr.
UpstateWeb LLC

Answers

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395

    Your DataTable initialisation is wrong.

    $('#example').dataTable( {
            "columnDefs": [
                {
                   "targets": [ 0, 5 ],
                    orderable: false 
                  },
              ]
        } );
    

    The default value of "orderable" and "visible" is "true", so it is not necessary to apply them to your other columns.

  • upstatewebupstateweb Posts: 4Questions: 2Answers: 0
    edited June 2015

    I figured out I had to make two separate Javascripts. The first included your code and I removed the class="init", followed by the Javascript for manipulating the buttons. The only problem I have now is when I put in 0,5, the 5th column's order tab goes away but the 1st column does not which will be a check box when I use it.

    Thanks for your help. I will keep digging. I only put this here to help those of us who need "DataTables for Dummies" help. Great product by the way.

This discussion has been closed.