-
Notifications
You must be signed in to change notification settings - Fork 6
/
igsv-datatables.js
66 lines (62 loc) · 2.26 KB
/
igsv-datatables.js
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
57
58
59
60
61
62
63
64
65
66
/**
* Inline Google Spreadsheet Viewer's DataTables integrations.
*
* @file Loads and applies DataTables to any tables on the page.
* @license GPL-3.0
*/
(function () { // start immediately-invoked function expresion (IIFE)
// DataTables
jQuery(document).ready(function () {
// Set/load defaults.
if (igsv_plugin_vars.datatables_defaults_object) {
jQuery.extend(jQuery.fn.dataTable.defaults, igsv_plugin_vars.datatables_defaults_object);
} else {
igsv_plugin_vars.datatables_defaults_object = {};
}
// Initialize tables.
jQuery(igsv_plugin_vars.datatables_classes).each(function () {
var table = jQuery(this);
var dt_opts = {};
if (jQuery.fn.dataTable.defaults.buttons) { // apply defaults for Buttons
dt_opts.buttons = jQuery.fn.dataTable.defaults.buttons
}
if (false === table.hasClass('no-responsive')) {
dt_opts.responsive = true;
}
if (table.attr('lang')) {
dt_opts.language = {
'url': igsv_plugin_vars.lang_dir + '/datatables-' + table.attr('lang') + '.json'
}
}
table.DataTable(dt_opts);
var x;
if (table.is('.FixedHeader')) {
new jQuery.fn.dataTable.FixedHeader(table);
} else if (x = this.className.match(/FixedHeader-(top|right|footer|left)/g)) {
for (var i = 0; i < x.length; i++) {
var side = x[i].split('-')[1];
var fheader_opts = {};
fheader_opts[side] = true;
}
new jQuery.fn.dataTable.FixedHeader(table, fheader_opts);
} else if (table.is('.FixedColumns')) {
new jQuery.fn.dataTable.FixedColumns(table);
} else if (x = this.className.match(/FixedColumns-(left|right)-([0-9])*/g)) {
var l_n = 0;
var r_n = 0;
for (var i = 0; i < x.length; i++) {
var z = x[i].split('-');
if ('left' === z[1]) {
l_n = z[2];
} else {
r_n = z[2];
}
}
new jQuery.fn.dataTable.FixedColumns(table, {
'leftColumns': l_n,
'rightColumns': r_n
});
}
});
});
})(); // end IIFE