I've tried for days and days with no luck on this. I have a wordpress site with an active theme and a working datatable. In the past, I've had to modify the typical datatable code a bit to get it to work right with scrolling and fixed search bar, etc.
The current problem is my column visibility button will not show up in any way, shape or form. If I copy the code to my test site, it works perfectly, so I know the code is technically right and the includes/css are right but I'm wondering if there's a different way to do this in a wordpress environment, maybe by appending the button or something.
The live site with the table (button not showing up) is testing.uwsinc.net/dashboardtest
Any help with this at all is much appreciated.
<head>
<title>Dashboard</title>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.15/css/jquery.dataTables.min.css" />
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/buttons/1.3.1/css/buttons.dataTables.min.css" />
<script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.js"></script>
<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/dataTables.buttons.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.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" src="https://cdn.rawgit.com/bpampuch/pdfmake/0.1.27/build/pdfmake.min.js"></script>
<script type="text/javascript" src="https://cdn.rawgit.com/bpampuch/pdfmake/0.1.27/build/vfs_fonts.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/buttons/1.3.1/js/buttons.html5.min.js"></script>
<style type="text/css">
#select-tables{
width: 250px;
}
table,td,th{
border:1px solid black;
}
table{
border-collapse: collapse;
width:100%;
}
td{
border-collapse: collapse;
/*border-right: none;
border-left: none;*/
}
th{
padding-left: 10px;
padding-right:10px;
}
td{
padding-left: 10px;
padding-right:10px;
}
input[type=submit]{
border: 1px solid grey;
color:black;
font-size:12px;
}
table.dataTable tbody th,
table.dataTable tbody td {
white-space: nowrap;
}
.dataTables_scroll
{
overflow:auto;
width: 965px;
}
.datatable{
width: 100% !important;
}
a.dt-button{
color:red;
}
</style>
</head>
<body>
//this section creates a drop down to show/hide one of the 2 tables
<label style="font-weight:bold;">Select the table you would like to view:</label></br>
<select name='tables' id='select-tables'>
<option value="mytable">Survey Test Table</option>
<option value="mytableSurvey">Survey Only</option>
</select>
</br>
//this code starts the datatables
<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" />');
$(document).on('change' , '#select-tables', function(){
var table = $(this).val();
$('#' + table +'_wrapper').show();
$('[id$="_wrapper"]').not('#' + table +'_wrapper').hide();
});
$("#select-tables").trigger("change");
});
}(jQuery));
</script>
UPDATE:
New method to hide dynamically, also not working:
<script type="text/javascript">
(function($) {
$(document).ready(function() {
var table = $('#mytable').DataTable({
});
$('a.toggle-vis').on( 'click', function (e) {
e.preventDefault();
// Get the column API object
var column = table.column( $(this).attr('data-column') );
// Toggle the visibility
column.visible( ! column.visible() );
} );
$('.dataTable').wrap('<div class="dataTables_scroll" />');
$(document).on('change' , '#select-tables', function(){
var table = $(this).val();
$('#' + table +'_wrapper').show();
$('[id$="_wrapper"]').not('#' + table +'_wrapper').hide();
});
$("#select-tables").trigger("change");
});
}(jQuery));
</script>