column visibility not working

column visibility not working

hnorman138hnorman138 Posts: 12Questions: 5Answers: 0
edited June 2017 in Free community support

I have 2 perfectly working datatables, but when trying to get column visibility (option to drop/hide certain columns) the option doesn't show up at all, it just shows my other dropdown options. In addition to the code below, I've also added all necessary CSS files.

<script type="text/javascript"   src="https://cdn.datatables.net/1.10.15/js/jquery.dataTables.min.js"></script>
<script type="text/javascript"   src="https://cdn.datatables.net/buttons/1.3.1/js/buttons.colVis.min.js"></script>
<script type="text/javascript">
(function($) {
$(document).ready(function() {
   $('#mytable').DataTable({
        dom: 'Blfrtip',
        buttons: [
            'colvis'
        ]
    });
   $('#mytableSurvey').DataTable({
        dom: 'Blfrtip',
        buttons: [
            'colvis'
        ]
    });
   $('.dataTable').wrap('<div class="dataTables_scroll" />');

   // select change event
   //$(document).on('change' , '#select-tables', function(){
    // var table = $(this).val();
     //$('#' + table +'_wrapper').show();
     //$('[id$="_wrapper"]').not('#' + table +'_wrapper').hide();
    //}).change();
    
     $(document).on('change' , '#select-tables', function(){
 var table = $(this).val();
 $('#' + table +'_wrapper').show();
 $('[id$="_wrapper"]').not('#' + table +'_wrapper').hide();
});
$("#select-tables").trigger("change");

});
}(jQuery));

Answers

  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin

    You need to include the Buttons core library as well:

    https://cdn.datatables.net/buttons/1.3.1/js/dataTables.buttons.min.js

    The download builder is available to make sure that all dependencies are satisfied.

    Allan

  • hnorman138hnorman138 Posts: 12Questions: 5Answers: 0

    Thank you for the answer, I have actually included that now as well as using the download builder but it's not working. However, the code with all included libraries/CSS works on my test site, just not on this wordpress site. I'm wondering if something's conflicting.

  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin

    Can you provide a link to your test site so we can take a look please?

    Allan

  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin

    This conversation seems to be happening in two different places.

    I'm closing this discussion as a duplicate.

    Allan

This discussion has been closed.