var TableAdvanced = function () {
    var initTable1 = function () {
        var table = $('#sample_1');
        $.extend(true, $.fn.DataTable.TableTools.classes, {"container": "btn-group tabletools-dropdown-on-portlet", "buttons": {"normal": "btn btn-sm default", "disabled": "btn btn-sm default disabled"}, "collection": {"container": "DTTT_dropdown dropdown-menu tabletools-dropdown-menu"}});
        var oTable = table.dataTable({"language": {"aria": {"sortAscending": ": activate to sort column ascending", "sortDescending": ": activate to sort column descending"}, "emptyTable": "No data available in table", "info": "Showing _START_ to _END_ of _TOTAL_ entries", "infoEmpty": "No entries found", "infoFiltered": "(filtered1 from _MAX_ total entries)", "lengthMenu": "_MENU_", "search": "", "zeroRecords": "No matching records found"}, "order": [[0, 'asc']], "lengthMenu": [[5, 10, 15, 20, -1], [5, 10, 15, 20, "All"]], "pageLength": 10, "dom": "<'row' <'col-md-12'T>><'row'<'col-md-6 col-sm-12'l><'col-md-6 col-sm-12'f>r><'table-scrollable't><'row'<'col-md-5 col-sm-12'i><'col-md-7 col-sm-12'p>>", "tableTools": {"sSwfPath": "../../assets/global/plugins/datatables/extensions/TableTools/swf/copy_csv_xls_pdf.swf", "aButtons": [{"sExtends": "pdf", "sButtonText": "PDF"}, {"sExtends": "csv", "sButtonText": "CSV"}, {"sExtends": "xls", "sButtonText": "Excel"}, {"sExtends": "print", "sButtonText": "Print", "sInfo": 'Please press "CTR+P" to print or "ESC" to quit', "sMessage": "Generated by DataTables"}]}});
        var tableWrapper = $('#sample_1_wrapper');
        tableWrapper.find('.dataTables_length select').select2();
    }
    var initTable2 = function () {
        var table = $('#sample_2');
        $.extend(true, $.fn.DataTable.TableTools.classes, {"container": "btn-group tabletools-btn-group pull-right", "buttons": {"normal": "btn btn-sm default", "disabled": "btn btn-sm default disabled"}});
        var oTable = table.dataTable({"language": {"aria": {"sortAscending": ": activate to sort column ascending", "sortDescending": ": activate to sort column descending"}, "emptyTable": "No data available in table", "info": "Showing _START_ to _END_ of _TOTAL_ entries", "infoEmpty": "No entries found", "infoFiltered": "(filtered1 from _MAX_ total entries)", "lengthMenu": "_MENU_", "search": "", "zeroRecords": "No matching records found"}, "order": [[0, 'asc']], "lengthMenu": [[5, 10, 15, 20, -1], [5, 10, 15, 20, "All"]], "pageLength": 10, "dom": "<'row' <'col-md-12'T>><'row'<'col-md-6 col-sm-12'l><'col-md-6 col-sm-12'f>r><'table-scrollable't><'row'<'col-md-5 col-sm-12'i><'col-md-7 col-sm-12'p>>", //
            "tableTools": {"sSwfPath": "../../assets/global/plugins/datatables/extensions/TableTools/swf/copy_csv_xls_pdf.swf", "aButtons": [{"sExtends": "pdf", "sButtonText": "PDF"}, {"sExtends": "csv", "sButtonText": "CSV"}, {"sExtends": "xls", "sButtonText": "Excel"}, {"sExtends": "print", "sButtonText": "Print", "sInfo": 'Please press "CTRL+P" to print or "ESC" to quit', "sMessage": "Generated by DataTables"}, {"sExtends": "copy", "sButtonText": "Copy"}]}});
        var tableWrapper = $('#sample_2_wrapper');
        tableWrapper.find('.dataTables_length select').select2();
    }
    var initTable3 = function () {
        var table = $('#sample_3');
        function fnFormatDetails(oTable, nTr) {
            var aData = oTable.fnGetData(nTr);
            var sOut = '<table>';
            sOut += '<tr><td>Platform(s):</td><td>' + aData[2] + '</td></tr>';
            sOut += '<tr><td>Engine version:</td><td>' + aData[3] + '</td></tr>';
            sOut += '<tr><td>CSS grade:</td><td>' + aData[4] + '</td></tr>';
            sOut += '<tr><td>Others:</td><td>Could provide a link here</td></tr>';
            sOut += '</table>';
            return sOut;
        }
        var nCloneTh = document.createElement('th');
        nCloneTh.className = "table-checkbox";
        var nCloneTd = document.createElement('td');
        nCloneTd.innerHTML = '<span class="row-details row-details-close"></span>';
        table.find('thead tr').each(function () {
            this.insertBefore(nCloneTh, this.childNodes[0]);
        });
        table.find('tbody tr').each(function () {
            this.insertBefore(nCloneTd.cloneNode(true), this.childNodes[0]);
        });
        var oTable = table.dataTable({"language": {"aria": {"sortAscending": ": activate to sort column ascending", "sortDescending": ": activate to sort column descending"}, "emptyTable": "No data available in table", "info": "Showing _START_ to _END_ of _TOTAL_ entries", "infoEmpty": "No entries found", "infoFiltered": "(filtered1 from _MAX_ total entries)", "lengthMenu": "_MENU_", "search": "", "zeroRecords": "No matching records found"}, "columnDefs": [{"orderable": false, "targets": [0]}], "order": [[1, 'asc']], "lengthMenu": [[5, 10, 15, 20, -1], [5, 10, 15, 20, "All"]], "pageLength": 10, });
        var tableWrapper = $('#sample_3_wrapper');
        tableWrapper.find('.dataTables_length select').select2();/**/
        table.on('click', ' tbody td .row-details', function () {
            var nTr = $(this).parents('tr')[0];
            if (oTable.fnIsOpen(nTr)) {
                $(this).addClass("row-details-close").removeClass("row-details-open");
                oTable.fnClose(nTr);
            } else {
                $(this).addClass("row-details-open").removeClass("row-details-close");
                oTable.fnOpen(nTr, fnFormatDetails(oTable, nTr), 'details');
            }
        });
    }
    var initTable4 = function () {
        var table = $('#sample_4');
        function fnFormatDetails(oTable, nTr) {
            var aData = oTable.fnGetData(nTr);
            var sOut = '<table>';
            sOut += '<tr><td>Platform(s):</td><td>' + aData[2] + '</td></tr>';
            sOut += '<tr><td>Engine version:</td><td>' + aData[3] + '</td></tr>';
            sOut += '<tr><td>CSS grade:</td><td>' + aData[4] + '</td></tr>';
            sOut += '<tr><td>Others:</td><td>Could provide a link here</td></tr>';
            sOut += '</table>';
            return sOut;
        }
        var nCloneTh = document.createElement('th');
        nCloneTh.className = "table-checkbox";
        var nCloneTd = document.createElement('td');
        nCloneTd.innerHTML = '<span class="row-details row-details-close"></span>';
        table.find('thead tr').each(function () {
            this.insertBefore(nCloneTh, this.childNodes[0]);
        });
        table.find('tbody tr').each(function () {
            this.insertBefore(nCloneTd.cloneNode(true), this.childNodes[0]);
        });
        var oTable = table.dataTable({"language": {"aria": {"sortAscending": ": activate to sort column ascending", "sortDescending": ": activate to sort column descending"}, "emptyTable": "No data available in table", "info": "Showing _START_ to _END_ of _TOTAL_ entries", "infoEmpty": "No entries found", "infoFiltered": "(filtered1 from _MAX_ total entries)", "lengthMenu": "_MENU_", "search": "", "zeroRecords": "No matching records found"}, "columnDefs": [{"orderable": false, "targets": [0]}], "order": [[1, 'asc']], "lengthMenu": [[5, 10, 15, 20, -1], [5, 10, 15, 20, "All"]], //
            "pageLength": 10, });
        var tableWrapper = $('#sample_4_wrapper');
        var tableColumnToggler = $('#sample_4_column_toggler');
        tableWrapper.find('.dataTables_length select').select2();
        table.on('click', ' tbody td .row-details', function () {
            var nTr = $(this).parents('tr')[0];
            if (oTable.fnIsOpen(nTr)) {
                $(this).addClass("row-details-close").removeClass("row-details-open");
                oTable.fnClose(nTr);
            } else {
                $(this).addClass("row-details-open").removeClass("row-details-close");
                oTable.fnOpen(nTr, fnFormatDetails(oTable, nTr), 'details');
            }
        });
        $('input[type="checkbox"]', tableColumnToggler).change(function () {
            var iCol = parseInt($(this).attr("data-column"));
            var bVis = oTable.fnSettings().aoColumns[iCol].bVisible;
            oTable.fnSetColumnVis(iCol, (bVis ? false : true));
        });
    }
    var initTable5 = function () {
        var table = $('#sample_5');
        var oTable = table.dataTable({"dom": "<'row'<'col-md-6 col-sm-12'l><'col-md-6 col-sm-12'f>r>t<'row'<'col-md-5 col-sm-12'i><'col-md-7 col-sm-12'p>>", "scrollY": "300", "deferRender": true, "order": [[0, 'asc']], "lengthMenu": [[5, 10, 15, 20, -1], [5, 10, 15, 20, "All"]], "pageLength": 10});
        var tableWrapper = $('#sample_5_wrapper');
        tableWrapper.find('.dataTables_length select').select2();
    }
    var initTable6 = function () {
        var table = $('#sample_6');
        var oTable = table.dataTable({"language": {"aria": {"sortAscending": ": activate to sort column ascending", "sortDescending": ": activate to sort column descending"}, "emptyTable": "No data available in table", "info": "Showing _START_ to _END_ of _TOTAL_ entries", "infoEmpty": "No entries found", "infoFiltered": "(filtered1 from _MAX_ total entries)", "lengthMenu": "_MENU_", "search": "", "zeroRecords": "No matching records found"}, "order": [[0, 'asc']], "lengthMenu": [[5, 10, 15, 20, -1], [5, 10, 15, 20, "All"]], "pageLength": 10, "columnDefs": [{'orderable': false, 'targets': [0]}, {"searchable": false, "targets": [0]
                }], "order":[[1, "asc"]]});
        var oTableColReorder = new $.fn.dataTable.ColReorder(oTable);
        var tableWrapper = $('#sample_6_wrapper');
        tableWrapper.find('.dataTables_length select').select2();
    }
    return{init: function () {
            if (!jQuery().dataTable) {
                return;
            }
            console.log('me 1');
            initTable1();
            initTable2();
            initTable3();
            initTable4();
            initTable5();
            initTable6();
            console.log('me 2');
        }};
}();