'use strict'; $(document).on('page_ready', function() { var maintable = $('#pending_table'), subtables, startTimeCol = maintable.find('thead tr:first th.header_start_time').index(), tableOptions, pendingDataTable, i, colVisIncludeCols; maintable.find('table.sub th.control') .text('-'); $(document).on('click', 'table.sub th.control', function () { var nTr = $(this).closest('.table_container').parent().prev(), serial = $(this).parent().parent().parent().attr('id').replace('subtable_', ''); $('#subtable_' + serial + '_wrapper').slideUp( function () { pendingDataTable.row(nTr).child.hide(); nTr.show(); }); }); subtables = maintable.find('tr.sub_table').detach(); maintable.find('td.control') .text('+'); $(document).on('click', 'td.control', function () { var nTr = $(this).parent(), serial = nTr.attr('id').replace('row_', ''), subtableId = 'subtable_' + serial, subtable = subtables.find('#' + subtableId).parent().clone(), columnDefs = [], subDataTable; maintable.find('tr').eq(0).find('th').each(function(i){ columnDefs.push({width: ($(this).outerWidth()) + "px", targets: i}); }); columnDefs.push({orderable: false, targets: 0}); columnDefs = columnDefs.concat(getTypes(subtable)); nTr.hide(); pendingDataTable.row(nTr).child(subtable.get(0)).show(); subtable.closest('td').addClass('table_container'); subDataTable = $('#' + subtableId).DataTable({autoWidth: false, paging: false, dom: 't', order: [[startTimeCol, 'asc']], columnDefs: columnDefs}); $('#subtable_' + serial + '_wrapper').hide().slideDown(); }); tableOptions = {order: [[startTimeCol, 'asc']]}; tableOptions.columnDefs = [{orderable: false, targets: 0}]; tableOptions.columnDefs = tableOptions.columnDefs.concat(getTypes(maintable)); tableOptions.stateSave = false; colVisIncludeCols = []; for (i=1; i tableOptions.colReorder = {"fixedColumnsLeft": 1}; pendingDataTable = makeDataTable('#pending_table', tableOptions); });