Subversion-Projekte lars-tiefland.cienc

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
9 lars 1
var TableDatatablesAjax = function () {
2
 
3
    var initPickers = function () {
4
        //init date pickers
5
        $('.date-picker').datepicker({
6
            rtl: App.isRTL(),
7
            autoclose: true
8
        });
9
    }
10
 
11
    var handleDemo1 = function () {
12
 
13
        var grid = new Datatable();
14
 
15
        grid.init({
16
            src: $("#datatable_ajax"),
17
            onSuccess: function (grid, response) {
18
                // grid:        grid object
19
                // response:    json object of server side ajax response
20
                // execute some code after table records loaded
21
            },
22
            onError: function (grid) {
23
                // execute some code on network or other general error
24
            },
25
            onDataLoad: function(grid) {
26
                // execute some code on ajax data load
27
            },
28
            loadingMessage: 'Loading...',
29
            dataTable: { // here you can define a typical datatable settings from http://datatables.net/usage/options
30
 
31
                // Uncomment below line("dom" parameter) to fix the dropdown overflow issue in the datatable cells. The default datatable layout
32
                // setup uses scrollable div(table-scrollable) with overflow:auto to enable vertical scroll(see: assets/global/scripts/datatable.js).
33
                // So when dropdowns used the scrollable div should be removed.
34
                //"dom": "<'row'<'col-md-8 col-sm-12'pli><'col-md-4 col-sm-12'<'table-group-actions pull-right'>>r>t<'row'<'col-md-8 col-sm-12'pli><'col-md-4 col-sm-12'>>",
35
 
36
                "bStateSave": true, // save datatable state(pagination, sort, etc) in cookie.
37
 
38
                "lengthMenu": [
39
                    [10, 20, 50, 100, 150, -1],
40
                    [10, 20, 50, 100, 150, "All"] // change per page values here
41
                ],
42
                "pageLength": 10, // default record count per page
43
                "ajax": {
44
                    "url": "../demo/table_ajax.php", // ajax source
45
                },
46
                "order": [
47
                    [1, "asc"]
48
                ]// set first column as a default sort by asc
49
            }
50
        });
51
 
52
        // handle group actionsubmit button click
53
        grid.getTableWrapper().on('click', '.table-group-action-submit', function (e) {
54
            e.preventDefault();
55
            var action = $(".table-group-action-input", grid.getTableWrapper());
56
            if (action.val() != "" && grid.getSelectedRowsCount() > 0) {
57
                grid.setAjaxParam("customActionType", "group_action");
58
                grid.setAjaxParam("customActionName", action.val());
59
                grid.setAjaxParam("id", grid.getSelectedRows());
60
                grid.getDataTable().ajax.reload();
61
                grid.clearAjaxParams();
62
            } else if (action.val() == "") {
63
                App.alert({
64
                    type: 'danger',
65
                    icon: 'warning',
66
                    message: 'Please select an action',
67
                    container: grid.getTableWrapper(),
68
                    place: 'prepend'
69
                });
70
            } else if (grid.getSelectedRowsCount() === 0) {
71
                App.alert({
72
                    type: 'danger',
73
                    icon: 'warning',
74
                    message: 'No record selected',
75
                    container: grid.getTableWrapper(),
76
                    place: 'prepend'
77
                });
78
            }
79
        });
80
 
81
        //grid.setAjaxParam("customActionType", "group_action");
82
        //grid.getDataTable().ajax.reload();
83
        //grid.clearAjaxParams();
84
    }
85
 
86
    var handleDemo2 = function () {
87
 
88
        var grid = new Datatable();
89
 
90
        grid.init({
91
            src: $("#datatable_ajax_2"),
92
            onSuccess: function (grid, response) {
93
                // grid:        grid object
94
                // response:    json object of server side ajax response
95
                // execute some code after table records loaded
96
            },
97
            onError: function (grid) {
98
                // execute some code on network or other general error
99
            },
100
            onDataLoad: function(grid) {
101
                // execute some code on ajax data load
102
            },
103
 
104
            dataTable: { // here you can define a typical datatable settings from http://datatables.net/usage/options
105
 
106
                // Uncomment below line("dom" parameter) to fix the dropdown overflow issue in the datatable cells. The default datatable layout
107
                // setup uses scrollable div(table-scrollable) with overflow:auto to enable vertical scroll(see: assets/global/scripts/datatable.js).
108
                // So when dropdowns used the scrollable div should be removed.
109
                //"dom": "<'row'<'col-md-8 col-sm-12'pli><'col-md-4 col-sm-12'<'table-group-actions pull-right'>>r>t<'row'<'col-md-8 col-sm-12'pli><'col-md-4 col-sm-12'>>",
110
 
111
                "dom": "<'row'<'col-md-8 col-sm-12'i><'col-md-4 col-sm-12'<'table-group-actions pull-right'>>r>t<'row'<'col-md-8 col-sm-12'i><'col-md-4 col-sm-12'>>",
112
 
113
                "bStateSave": true, // save datatable state(pagination, sort, etc) in cookie.
114
 
115
                "pageLength": 10, // default record count per page
116
 
117
                "ajax": {
118
                    "url": "../demo/table_ajax.php", // ajax source
119
                },
120
                "order": [
121
                    [1, "asc"]
122
                ],// set first column as a default sort by asc,
123
 
124
                "language": {
125
                    "loadingRecords": "Please wait ...",
126
                    "zeroRecords": "No records",
127
                    "emptyTable": "No data available in table",
128
                    "info": "Showing _START_ to _END_ of _TOTAL_ entries",
129
                },
130
 
131
                scrollY: 400,
132
                deferRender:    true,
133
                scroller: {
134
                    loadingIndicator: true
135
                }
136
            }
137
        });
138
 
139
        // handle group actionsubmit button click
140
        grid.getTableWrapper().on('click', '.table-group-action-submit', function (e) {
141
            e.preventDefault();
142
            var action = $(".table-group-action-input", grid.getTableWrapper());
143
            if (action.val() != "" && grid.getSelectedRowsCount() > 0) {
144
                grid.setAjaxParam("customActionType", "group_action");
145
                grid.setAjaxParam("customActionName", action.val());
146
                grid.setAjaxParam("id", grid.getSelectedRows());
147
                grid.getDataTable().ajax.reload();
148
                grid.clearAjaxParams();
149
            } else if (action.val() == "") {
150
                App.alert({
151
                    type: 'danger',
152
                    icon: 'warning',
153
                    message: 'Please select an action',
154
                    container: grid.getTableWrapper(),
155
                    place: 'prepend'
156
                });
157
            } else if (grid.getSelectedRowsCount() === 0) {
158
                App.alert({
159
                    type: 'danger',
160
                    icon: 'warning',
161
                    message: 'No record selected',
162
                    container: grid.getTableWrapper(),
163
                    place: 'prepend'
164
                });
165
            }
166
        });
167
 
168
        //grid.setAjaxParam("customActionType", "group_action");
169
        //grid.getDataTable().ajax.reload();
170
        //grid.clearAjaxParams();
171
    }
172
 
173
    return {
174
 
175
        //main function to initiate the module
176
        init: function () {
177
 
178
            initPickers();
179
            handleDemo1();
180
            handleDemo2();
181
        }
182
 
183
    };
184
 
185
}();
186
 
187
jQuery(document).ready(function() {
188
    TableDatatablesAjax.init();
189
});