Bug 16759: Use index of elements in specific table
[koha.git] / koha-tmpl / opac-tmpl / bootstrap / en / includes / columns_settings.inc
1 [% USE ColumnsSettings %]
2
3 <script type="text/javascript">
4 function KohaTable(selector, dt_parameters, columns_settings) {
5     var id = 0;
6     var hidden_ids = [];
7     var included_ids = [];
8     $(columns_settings).each( function() {
9         var named_id = $( 'thead th[data-colname="' + this.columnname + '"]', selector ).index( selector+' th' );
10
11         var used_id = dt_parameters.bKohaColumnsUseNames ? named_id : id;
12         if ( used_id == -1 ) return;
13
14         if ( this['is_hidden'] == "1" ) {
15             hidden_ids.push( used_id );
16         }
17         if ( this['cannot_be_toggled'] == "0" ) {
18             included_ids.push( used_id );
19         }
20         id++;
21     });
22     dt_parameters[ "buttons" ] = [
23         {
24             extend: 'colvis',
25             columns: included_ids,
26             text: _("Column visibility"),
27         }
28     ];
29     var table = $(selector).dataTable($.extend(true, {}, dataTablesDefaults, dt_parameters));
30
31     $(hidden_ids).each(function(index, value) {
32         table.fnSetColumnVis( value, false );
33     });
34
35     return table;
36 }
37
38 </script>