<!-- PAGE LEVEL SCRIPTS -->
<script type="text/javascript">
    loadScript(plugin_path + "datatables/js/jquery.dataTables.min.js", function(){
        loadScript(plugin_path + "datatables/js/dataTables.tableTools.min.js", function(){
            loadScript(plugin_path + "datatables/js/dataTables.colReorder.min.js", function(){
                loadScript(plugin_path + "datatables/js/dataTables.scroller.min.js", function(){
                    loadScript(plugin_path + "datatables/dataTables.bootstrap.js", function(){
                        loadScript(plugin_path + "select2/js/select2.full.min.js", function(){

                            if (jQuery().dataTable) {

                                // Columns Reorder
                                function initTable() {

                                    var table = jQuery('#sample_5');

                                    /* Fixed header extension: http://datatables.net/extensions/keytable/ */

                                    var oTable = table.dataTable({
                                        "order": [
                                            [0, 'desc']
                                        ],
                                        "lengthMenu": [
                                            [5, 15, 20, -1],
                                            [5, 15, 20, "All"] // change per page values here
                                        ],
                                        "pageLength": 20, // set the initial value,
                                        "columnDefs": [{  // set default column settings
                                            'orderable': false,
                                            'targets': [0]
                                        }, {
                                            "searchable": false,
                                            "targets": [0]
                                        }]
                                    });

                                    var oTableColReorder = new jQuery.fn.dataTable.ColReorder( oTable );

                                    var tableWrapper = jQuery('#sample_6_wrapper'); // datatable creates the table wrapper by adding with id {your_table_jd}_wrapper
                                    tableWrapper.find('.dataTables_length select').select2(); // initialize select2 dropdown
                                    table.on('click', '.delete', function (e) {
                                        e.preventDefault();

                                        if (confirm("Are you sure to delete this row ?") == false) {
                                            return;
                                        }

                                        var nRow = $(this).parents('tr')[0];
                                        oTable.fnDeleteRow(nRow);

                                        var href = $(this).attr('href');

                                        $.ajax({
                                            type: "POST",
                                            url: href,
                                            success:function(data){
                                                if(data==200) {
                                                    _toastr("Delete successful...","top-right","success",false);
                                                }
                                                else{
                                                    _toastr("Delete failed!","top-right","error",false);
                                                }
                                            }
                                        }) ;
                                    });
                                }

                                initTable();

                            }

                        });
                    });
                });
            });
        });
    });
</script>