I'm creating some dynamic content tabs using PHP, one object on the tab is a datatable. I define the ID via PHP like this:
PHP:
echo '<table class="table table-striped table-bordered table-hover" id="'.$nospaces.'">';
The table loads the data perfectly however I'm having problems initializing the datatable for sorting and filtering. Normally on static tables I would just initialize it using the static ID but I can't do that in this case.
I thought I could do some jquery to listen to a tab click event and then grab the table ID and load it into the jquery datatables initialization but that isn't working either. I'm just getting an undefined alert:
JQuery:
<script>
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
var row = $(this).closest('table').attr('id');
alert(row);
$(document).ready(function() {
oTable = $('row').dataTable( {
"sDom": '<"top"lf>rt<"bottom"ip><"clear">'
});
});
});
</script>
Any help would be greatly appreciated! Thanks.