Lines 1-24
Link Here
|
1 |
[% USE TablesSettings %] |
1 |
[% USE TablesSettings %] |
2 |
|
2 |
|
3 |
<script> |
3 |
<script> |
4 |
function KohaTable(selector, dt_parameters, columns_settings) { |
4 |
|
5 |
var id = 0; |
5 |
function _dt_visibility(table_settings, table_dt){ |
6 |
var hidden_ids = []; |
6 |
let hidden_ids = []; |
7 |
var included_ids = []; |
7 |
if ( table_settings ) { |
8 |
$(columns_settings).each( function() { |
8 |
var columns_settings = table_settings.columns; |
9 |
var named_id = $( 'thead th[data-colname="' + this.columnname + '"]', selector ).index( selector+' th' ); |
9 |
let i = 0; |
10 |
|
10 |
let use_names = $(table_dt.table().node()).data('bKohaColumnsUseNames'); |
11 |
var used_id = dt_parameters.bKohaColumnsUseNames ? named_id : id; |
11 |
if ( use_names ) { |
12 |
if ( used_id == -1 ) return; |
12 |
let hidden_columns = table_settings.columns.filter(c => c.is_hidden); |
13 |
|
13 |
if (!hidden_columns.length) return []; |
14 |
if ( this['is_hidden'] == "1" ) { |
14 |
table_dt.columns(hidden_columns.map(c => "[data-colname='%s']".format(c.columnname)).join(',')).every(function(){ |
15 |
hidden_ids.push( used_id ); |
15 |
hidden_ids.push(this.index()); |
16 |
} |
16 |
}); |
17 |
if ( this['cannot_be_toggled'] == "0" ) { |
17 |
} else { |
18 |
included_ids.push( used_id ); |
18 |
$(columns_settings).each( function(i, c) { |
|
|
19 |
if ( c.is_hidden == '1' ) { |
20 |
hidden_ids.push(i); |
21 |
} |
22 |
}); |
19 |
} |
23 |
} |
20 |
id++; |
24 |
} |
21 |
}); |
25 |
return hidden_ids; |
|
|
26 |
} |
27 |
|
28 |
function KohaTable(selector, dt_parameters, table_settings) { |
22 |
|
29 |
|
23 |
// By default we include all visible columns in exports and print unless they have the "noExport" class |
30 |
// By default we include all visible columns in exports and print unless they have the "noExport" class |
24 |
var exportColumns = ":visible:not(.noExport)"; |
31 |
var exportColumns = ":visible:not(.noExport)"; |
Lines 79-90
function KohaTable(selector, dt_parameters, columns_settings) {
Link Here
|
79 |
} |
86 |
} |
80 |
]; |
87 |
]; |
81 |
|
88 |
|
82 |
if( included_ids.length > 0 ){ |
89 |
// Retrieving bKohaColumnsUseNames from the options passed to the constructor, not DT settings |
|
|
90 |
// But ideally should be retrieved using table.data() |
91 |
let use_names = dt_parameters.bKohaColumnsUseNames; |
92 |
let included_columns = []; |
93 |
if (table_settings) { |
94 |
if (use_names) { |
95 |
// bKohaColumnsUseNames is set, identify columns by their data-colname |
96 |
included_columns = table_settings.columns |
97 |
.filter(c => !c.cannot_be_toggled) |
98 |
.map(c => "[data-colname='%s']".format(c.columnname)) |
99 |
.join(","); |
100 |
} else { |
101 |
// Not set, columns are ordered the same than in the columns settings |
102 |
included_columns = table_settings.columns |
103 |
.map((c, i) => (!c.cannot_be_toggled ? i : null)) |
104 |
.filter(i => i !== null); |
105 |
} |
106 |
} |
107 |
|
108 |
if( included_columns.length > 0 ){ |
83 |
dt_parameters[ "buttons" ].push( |
109 |
dt_parameters[ "buttons" ].push( |
84 |
{ |
110 |
{ |
85 |
extend: 'colvis', |
111 |
extend: 'colvis', |
86 |
fade: 100, |
112 |
fade: 100, |
87 |
columns: included_ids, |
113 |
columns: included_columns, |
88 |
className: "columns_controls", |
114 |
className: "columns_controls", |
89 |
titleAttr: _("Columns settings"), |
115 |
titleAttr: _("Columns settings"), |
90 |
text: '<i class="fa fa-lg fa-gear" aria-hidden="true"></i> <span class="dt-button-text">' + _("Columns") + '</span>', |
116 |
text: '<i class="fa fa-lg fa-gear" aria-hidden="true"></i> <span class="dt-button-text">' + _("Columns") + '</span>', |
Lines 96-101
function KohaTable(selector, dt_parameters, columns_settings) {
Link Here
|
96 |
} |
122 |
} |
97 |
|
123 |
|
98 |
var table = $(selector); |
124 |
var table = $(selector); |
|
|
125 |
|
99 |
var new_parameters = {} |
126 |
var new_parameters = {} |
100 |
$.extend(true, new_parameters, dataTablesDefaults, dt_parameters); |
127 |
$.extend(true, new_parameters, dataTablesDefaults, dt_parameters); |
101 |
var default_column_defs = [ |
128 |
var default_column_defs = [ |
Lines 109-116
function KohaTable(selector, dt_parameters, columns_settings) {
Link Here
|
109 |
$.extend(true, new_parameters, default_column_defs); |
136 |
$.extend(true, new_parameters, default_column_defs); |
110 |
} |
137 |
} |
111 |
|
138 |
|
|
|
139 |
$(table).data('bKohaColumnsUseNames', dt_parameters.bKohaColumnsUseNames); |
140 |
|
112 |
table.dataTable(new_parameters); |
141 |
table.dataTable(new_parameters); |
113 |
table.DataTable().on("column-visibility.dt", function () { |
142 |
var table_dt = table.DataTable(); |
|
|
143 |
|
144 |
let hidden_ids = _dt_visibility(table_settings, table_dt); |
145 |
table_dt.on("column-visibility.dt", function () { |
114 |
if (typeof columnsInit == 'function') { |
146 |
if (typeof columnsInit == 'function') { |
115 |
// This function can be created separately and used to trigger |
147 |
// This function can be created separately and used to trigger |
116 |
// an event after the DataTable has loaded AND column visibility |
148 |
// an event after the DataTable has loaded AND column visibility |
Lines 119-126
function KohaTable(selector, dt_parameters, columns_settings) {
Link Here
|
119 |
} |
151 |
} |
120 |
}).columns(hidden_ids).visible(false); |
152 |
}).columns(hidden_ids).visible(false); |
121 |
|
153 |
|
122 |
$(".dt_button_clear_filter, .columns_controls, .export_controls").tooltip(); |
|
|
123 |
|
124 |
return table; |
154 |
return table; |
125 |
} |
155 |
} |
126 |
|
156 |
|