hjg
2024-01-20 4a3404efc438b16044fd9170814e6545a3f86fae
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
var TableAjax = function () {
 
    return {
 
        //main function to initiate the module
        init: function () {
            
            if (!jQuery().dataTable) {
                return;
            }
 
            // begin first table
            $('#sample_1').dataTable({
                "sDom" : "<'row'<'col-md-6 col-sm-12'l><'col-md-12 col-sm-12'f>r>t<'row'<'col-md-5 col-sm-12'i><'col-md-7 col-sm-12'p>>", //default layout without horizontal scroll(remove this setting to enable horizontal scroll for the table)
                "aLengthMenu": [
                    [10, 25, 50, 100, -1],
                    [10, 25, 50, 100, "All"] // change per page values here
                ],
                "bProcessing": true,
                "bServerSide": true,
                "sAjaxSource": "demo/table_ajax.php",
                // set the initial value
                "iDisplayLength": 10,
                "sPaginationType": "bootstrap",
                "oLanguage": {
                    "sProcessing": '<i class="fa fa-coffee"></i>&nbsp;Please wait...',
                    "sLengthMenu": "_MENU_ records",
                    "oPaginate": {
                        "sPrevious": "Prev",
                        "sNext": "Next"
                    }
                },
                "aoColumnDefs": [{
                        'bSortable': false,
                        'aTargets': [0]
                    }
                ]
            });
 
            jQuery('#sample_1_wrapper .dataTables_filter input').addClass("form-control input-medium"); // modify table search input
            jQuery('#sample_1_wrapper .dataTables_length select').addClass("form-control input-small"); // modify table per page dropdown
 
            // handle record edit/remove
            $('body').on('click', '#sample_1_wrapper .btn-editable', function() {
                alert('Edit record with id:' + $(this).attr("data-id"));
            });
 
            $('body').on('click', '#sample_1_wrapper .btn-removable', function() {
                alert('Remove record with id:' + $(this).attr("data-id"));
            });
 
        }
 
    };
 
}();