Bug 18791: Export visible columns only
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / includes / columns_settings.inc
blob636cc5a562ff19fe68788dc40232f8ebd1b296ec
1 [% USE ColumnsSettings %]
3 <script type="text/javascript">
4 function KohaTable(id_selector, dt_parameters, columns_settings, add_filters) {
5     var counter = 0;
6     var hidden_ids = [];
7     var included_ids = [];
8     var selector = '#' + id_selector;
10     $(columns_settings).each( function() {
11         var named_id = $( 'thead th[data-colname="' + this.columnname + '"]', selector ).index( 'th' );
12         var used_id = dt_parameters.bKohaColumnsUseNames ? named_id : counter;
13         if ( used_id == -1 ) return;
15         if ( this['is_hidden'] == "1" ) {
16             hidden_ids.push( used_id );
17         }
18         if ( this['cannot_be_toggled'] == "0" ) {
19             included_ids.push( used_id );
20         }
21         counter++;
22     });
23     dt_parameters[ "buttons" ] = [
24         {
25             extend: 'colvis',
26             columns: included_ids,
27             text: _("Column visibility"),
28             exportOptions: {
29                 columns: ':visible'
30             },
31         },
32         {
33             extend: 'excelHtml5',
34             text: _("Excel"),
35             exportOptions: {
36                 columns: ':visible'
37             },
38         },
39         {
40             extend: 'csvHtml5',
41             text: _("CSV"),
42             exportOptions: {
43                 columns: ':visible'
44             },
45         },
46         {
47             extend: 'copyHtml5',
48             text: _("Copy"),
49             exportOptions: {
50                 columns: ':visible'
51             },
52         },
53         {
54             extend: 'print',
55             text: _("Print"),
56             exportOptions: {
57                 columns: ':visible'
58             },
59         },
60     ];
62     var table = $(selector);
63     if ( add_filters ) {
64         // Duplicate the table header row for columnFilter
65         thead_row = table.find('thead tr');
66         clone = thead_row.clone().addClass('filters_row');
67         clone.find("th.NoSort").html('');
68         thead_row.before(clone);
69     }
71     table.dataTable($.extend(true, {}, dataTablesDefaults, dt_parameters));
73     $(hidden_ids).each(function(index, value) {
74         table.fnSetColumnVis( value, false );
75     });
77     if ( add_filters ) {
78         // show a link to activate filtering
79         link = $('<a>')
80             .attr('href', '#')
81             .attr('id', id_selector + '_activate_filters');
82         $("." + id_selector  + "_table_controls").prepend(link);
83         deactivate_filters(id_selector);
84     }
86     return table;
89 </script>