Subversion-Projekte lars-tiefland.cienc

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
9 lars 1
var TableDatatablesButtons = function () {
2
 
3
    var initTable1 = function () {
4
        var table = $('#sample_1');
5
 
6
        var oTable = table.dataTable({
7
 
8
            // Internationalisation. For more info refer to http://datatables.net/manual/i18n
9
            "language": {
10
                "aria": {
11
                    "sortAscending": ": activate to sort column ascending",
12
                    "sortDescending": ": activate to sort column descending"
13
                },
14
                "emptyTable": "No data available in table",
15
                "info": "Showing _START_ to _END_ of _TOTAL_ entries",
16
                "infoEmpty": "No entries found",
17
                "infoFiltered": "(filtered1 from _MAX_ total entries)",
18
                "lengthMenu": "_MENU_ entries",
19
                "search": "Search:",
20
                "zeroRecords": "No matching records found"
21
            },
22
 
23
            // Or you can use remote translation file
24
            //"language": {
25
            //   url: '//cdn.datatables.net/plug-ins/3cfcc339e89/i18n/Portuguese.json'
26
            //},
27
 
28
 
29
            buttons: [
30
                { extend: 'print', className: 'btn dark btn-outline' },
31
                { extend: 'copy', className: 'btn red btn-outline' },
32
                { extend: 'pdf', className: 'btn green btn-outline' },
33
                { extend: 'excel', className: 'btn yellow btn-outline ' },
34
                { extend: 'csv', className: 'btn purple btn-outline ' },
35
                { extend: 'colvis', className: 'btn dark btn-outline', text: 'Columns'}
36
            ],
37
 
38
            // setup responsive extension: http://datatables.net/extensions/responsive/
39
            responsive: true,
40
 
41
            //"ordering": false, disable column ordering
42
            //"paging": false, disable pagination
43
 
44
            "order": [
45
                [0, 'asc']
46
            ],
47
 
48
            "lengthMenu": [
49
                [5, 10, 15, 20, -1],
50
                [5, 10, 15, 20, "All"] // change per page values here
51
            ],
52
            // set the initial value
53
            "pageLength": 10,
54
 
55
            "dom": "<'row' <'col-md-12'B>><'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>>", // horizobtal scrollable datatable
56
 
57
            // Uncomment below line("dom" parameter) to fix the dropdown overflow issue in the datatable cells. The default datatable layout
58
            // setup uses scrollable div(table-scrollable) with overflow:auto to enable vertical scroll(see: assets/global/plugins/datatables/plugins/bootstrap/dataTables.bootstrap.js).
59
            // So when dropdowns used the scrollable div should be removed.
60
            //"dom": "<'row' <'col-md-12'T>><'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>>",
61
        });
62
    }
63
 
64
    var initTable2 = function () {
65
        var table = $('#sample_2');
66
 
67
        var oTable = table.dataTable({
68
 
69
            // Internationalisation. For more info refer to http://datatables.net/manual/i18n
70
            "language": {
71
                "aria": {
72
                    "sortAscending": ": activate to sort column ascending",
73
                    "sortDescending": ": activate to sort column descending"
74
                },
75
                "emptyTable": "No data available in table",
76
                "info": "Showing _START_ to _END_ of _TOTAL_ entries",
77
                "infoEmpty": "No entries found",
78
                "infoFiltered": "(filtered1 from _MAX_ total entries)",
79
                "lengthMenu": "_MENU_ entries",
80
                "search": "Search:",
81
                "zeroRecords": "No matching records found"
82
            },
83
 
84
            // Or you can use remote translation file
85
            //"language": {
86
            //   url: '//cdn.datatables.net/plug-ins/3cfcc339e89/i18n/Portuguese.json'
87
            //},
88
 
89
            buttons: [
90
                { extend: 'print', className: 'btn default' },
91
                { extend: 'copy', className: 'btn default' },
92
                { extend: 'pdf', className: 'btn default' },
93
                { extend: 'excel', className: 'btn default' },
94
                { extend: 'csv', className: 'btn default' },
95
                {
96
                    text: 'Reload',
97
                    className: 'btn default',
98
                    action: function ( e, dt, node, config ) {
99
                        //dt.ajax.reload();
100
                        alert('Custom Button');
101
                    }
102
                }
103
            ],
104
 
105
            "order": [
106
                [0, 'asc']
107
            ],
108
 
109
            "lengthMenu": [
110
                [5, 10, 15, 20, -1],
111
                [5, 10, 15, 20, "All"] // change per page values here
112
            ],
113
            // set the initial value
114
            "pageLength": 10,
115
 
116
            "dom": "<'row' <'col-md-12'B>><'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>>", // horizobtal scrollable datatable
117
 
118
            // Uncomment below line("dom" parameter) to fix the dropdown overflow issue in the datatable cells. The default datatable layout
119
            // setup uses scrollable div(table-scrollable) with overflow:auto to enable vertical scroll(see: assets/global/plugins/datatables/plugins/bootstrap/dataTables.bootstrap.js).
120
            // So when dropdowns used the scrollable div should be removed.
121
            //"dom": "<'row' <'col-md-12'T>><'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>>",
122
        });
123
    }
124
 
125
    var initTable3 = function () {
126
        var table = $('#sample_3');
127
 
128
        var oTable = table.dataTable({
129
 
130
            // Internationalisation. For more info refer to http://datatables.net/manual/i18n
131
            "language": {
132
                "aria": {
133
                    "sortAscending": ": activate to sort column ascending",
134
                    "sortDescending": ": activate to sort column descending"
135
                },
136
                "emptyTable": "No data available in table",
137
                "info": "Showing _START_ to _END_ of _TOTAL_ entries",
138
                "infoEmpty": "No entries found",
139
                "infoFiltered": "(filtered1 from _MAX_ total entries)",
140
                "lengthMenu": "_MENU_ entries",
141
                "search": "Search:",
142
                "zeroRecords": "No matching records found"
143
            },
144
 
145
            // Or you can use remote translation file
146
            //"language": {
147
            //   url: '//cdn.datatables.net/plug-ins/3cfcc339e89/i18n/Portuguese.json'
148
            //},
149
 
150
            buttons: [
151
                { extend: 'print', className: 'btn dark btn-outline' },
152
                { extend: 'copy', className: 'btn red btn-outline' },
153
                { extend: 'pdf', className: 'btn green btn-outline' },
154
                { extend: 'excel', className: 'btn yellow btn-outline ' },
155
                { extend: 'csv', className: 'btn purple btn-outline ' },
156
                { extend: 'colvis', className: 'btn dark btn-outline', text: 'Columns'}
157
            ],
158
 
159
            // setup responsive extension: http://datatables.net/extensions/responsive/
160
            responsive: true,
161
 
162
            //"ordering": false, disable column ordering
163
            //"paging": false, disable pagination
164
 
165
            "order": [
166
                [0, 'asc']
167
            ],
168
 
169
            "lengthMenu": [
170
                [5, 10, 15, 20, -1],
171
                [5, 10, 15, 20, "All"] // change per page values here
172
            ],
173
            // set the initial value
174
            "pageLength": 10,
175
 
176
            //"dom": "<'row' <'col-md-12'>><'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>>", // horizobtal scrollable datatable
177
 
178
            // Uncomment below line("dom" parameter) to fix the dropdown overflow issue in the datatable cells. The default datatable layout
179
            // setup uses scrollable div(table-scrollable) with overflow:auto to enable vertical scroll(see: assets/global/plugins/datatables/plugins/bootstrap/dataTables.bootstrap.js).
180
            // So when dropdowns used the scrollable div should be removed.
181
            //"dom": "<'row' <'col-md-12'T>><'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>>",
182
        });
183
 
184
        // handle datatable custom tools
185
        $('#sample_3_tools > li > a.tool-action').on('click', function() {
186
            var action = $(this).attr('data-action');
187
            oTable.DataTable().button(action).trigger();
188
        });
189
    }
190
 
191
    var initAjaxDatatables = function () {
192
 
193
        //init date pickers
194
        $('.date-picker').datepicker({
195
            rtl: App.isRTL(),
196
            autoclose: true
197
        });
198
 
199
        var grid = new Datatable();
200
 
201
        grid.init({
202
            src: $("#datatable_ajax"),
203
            onSuccess: function (grid, response) {
204
                // grid:        grid object
205
                // response:    json object of server side ajax response
206
                // execute some code after table records loaded
207
            },
208
            onError: function (grid) {
209
                // execute some code on network or other general error
210
            },
211
            onDataLoad: function(grid) {
212
                // execute some code on ajax data load
213
            },
214
            loadingMessage: 'Loading...',
215
            dataTable: { // here you can define a typical datatable settings from http://datatables.net/usage/options
216
 
217
                // Uncomment below line("dom" parameter) to fix the dropdown overflow issue in the datatable cells. The default datatable layout
218
                // setup uses scrollable div(table-scrollable) with overflow:auto to enable vertical scroll(see: assets/global/scripts/datatable.js).
219
                // So when dropdowns used the scrollable div should be removed.
220
 
221
                //"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'>>",
222
 
223
                "bStateSave": true, // save datatable state(pagination, sort, etc) in cookie.
224
 
225
                "lengthMenu": [
226
                    [10, 20, 50, 100, 150, -1],
227
                    [10, 20, 50, 100, 150, "All"] // change per page values here
228
                ],
229
                "pageLength": 10, // default record count per page
230
                "ajax": {
231
                    "url": "../demo/table_ajax.php", // ajax source
232
                },
233
                "order": [
234
                    [1, "asc"]
235
                ],// set first column as a default sort by asc
236
 
237
                // Or you can use remote translation file
238
                //"language": {
239
                //   url: '//cdn.datatables.net/plug-ins/3cfcc339e89/i18n/Portuguese.json'
240
                //},
241
 
242
                buttons: [
243
                    { extend: 'print', className: 'btn default' },
244
                    { extend: 'copy', className: 'btn default' },
245
                    { extend: 'pdf', className: 'btn default' },
246
                    { extend: 'excel', className: 'btn default' },
247
                    { extend: 'csv', className: 'btn default' },
248
                    {
249
                        text: 'Reload',
250
                        className: 'btn default',
251
                        action: function ( e, dt, node, config ) {
252
                            dt.ajax.reload();
253
                            alert('Datatable reloaded!');
254
                        }
255
                    }
256
                ],
257
 
258
            }
259
        });
260
 
261
        // handle group actionsubmit button click
262
        grid.getTableWrapper().on('click', '.table-group-action-submit', function (e) {
263
            e.preventDefault();
264
            var action = $(".table-group-action-input", grid.getTableWrapper());
265
            if (action.val() != "" && grid.getSelectedRowsCount() > 0) {
266
                grid.setAjaxParam("customActionType", "group_action");
267
                grid.setAjaxParam("customActionName", action.val());
268
                grid.setAjaxParam("id", grid.getSelectedRows());
269
                grid.getDataTable().ajax.reload();
270
                grid.clearAjaxParams();
271
            } else if (action.val() == "") {
272
                App.alert({
273
                    type: 'danger',
274
                    icon: 'warning',
275
                    message: 'Please select an action',
276
                    container: grid.getTableWrapper(),
277
                    place: 'prepend'
278
                });
279
            } else if (grid.getSelectedRowsCount() === 0) {
280
                App.alert({
281
                    type: 'danger',
282
                    icon: 'warning',
283
                    message: 'No record selected',
284
                    container: grid.getTableWrapper(),
285
                    place: 'prepend'
286
                });
287
            }
288
        });
289
 
290
        //grid.setAjaxParam("customActionType", "group_action");
291
        //grid.getDataTable().ajax.reload();
292
        //grid.clearAjaxParams();
293
 
294
        // handle datatable custom tools
295
        $('#datatable_ajax_tools > li > a.tool-action').on('click', function() {
296
            var action = $(this).attr('data-action');
297
            grid.getDataTable().button(action).trigger();
298
        });
299
    }
300
 
301
    return {
302
 
303
        //main function to initiate the module
304
        init: function () {
305
 
306
            if (!jQuery().dataTable) {
307
                return;
308
            }
309
 
310
            initTable1();
311
            initTable2();
312
            initTable3();
313
 
314
            initAjaxDatatables();
315
        }
316
 
317
    };
318
 
319
}();
320
 
321
jQuery(document).ready(function() {
322
    TableDatatablesButtons.init();
323
});