Buttons and default not visible columns

Buttons and default not visible columns

RayzerRayzer Posts: 3Questions: 1Answers: 0

Hi,

I am using the following script to my table.
My question is what do I need to change to make columns 2 and 3 not visible when the page loads?

<script>

$(document).ready(function() {
    $('#customers').DataTable({
        aoColumnDefs: [{ "bSortable": false, "aTargets": [ 0 ] }], 
        dom: 'Blfrtip', //'C<"clear">lfrtip <"wrapper">T',
        stateSave: true,
        stateDuration: -1,
        order: [[ 9, 'desc' ]],
        buttons: [
         'copy', 'csv', 'excel', 'pdf', 'print',
            {
                extend: 'colvis',
                postfixButtons: [ 'colvisRestore' ]
            }
        ],
        initComplete: function () {
            this.api().columns([1, 5]).every( function () {
                var column = this;
                var select = $('<select><option value="">No Filter</option></select>')
                    .appendTo( $(column.footer()).empty() )
                    .on( 'change', function () {
                        var val = $.fn.dataTable.util.escapeRegex(
                            $(this).val()
                        );
 
                        column
                            .search( val ? '^'+val+'$' : '', true, false )
                            .draw();
                    } );
 
                column.data().unique().sort().each( function ( d, j ) {
                    select.append( '<option value="'+d+'">'+d+'</option>' )
                } );
            } );
        }

        
        });
        

} );
</script>

This question has an accepted answers - jump to answer

Answers

  • RayzerRayzer Posts: 3Questions: 1Answers: 0

    PS. I used to do the following when using tableTools, but as this was replaced with Buttons I can no longer use the below function.

    columnDefs: [
                { visible: false, targets: [ 6, 7, 8, 9, 10, 11, 21 ] },
                { orderable: false, targets: [ 0 ] }
    
  • tangerinetangerine Posts: 3,350Questions: 37Answers: 394
    Answer ✓

    AFAIK the columnDefs options have nothing to do with TableTools. Why can't you use those settings?

  • RayzerRayzer Posts: 3Questions: 1Answers: 0

    @tangerine You were correct... noob mistake, I had the save state enabled so when I was setting the targets to not visible, it was remembering the save state status of each of the columns and therefore not hiding them.

    Thanks

This discussion has been closed.