Bug 18791: Add the ability for librarians to easily copy, download or print DataTable...
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / includes / columns_settings.inc
1 [% USE ColumnsSettings %]
2
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;
9
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;
14
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         },
29         'excelHtml5',
30         'csvHtml5',
31         'copyHtml5',
32         'print',
33     ];
34
35     var table = $(selector);
36     if ( add_filters ) {
37         // Duplicate the table header row for columnFilter
38         thead_row = table.find('thead tr');
39         clone = thead_row.clone().addClass('filters_row');
40         clone.find("th.NoSort").html('');
41         thead_row.before(clone);
42     }
43
44     table.dataTable($.extend(true, {}, dataTablesDefaults, dt_parameters));
45
46     $(hidden_ids).each(function(index, value) {
47         table.fnSetColumnVis( value, false );
48     });
49
50     if ( add_filters ) {
51         // show a link to activate filtering
52         link = $('<a>')
53             .attr('href', '#')
54             .attr('id', id_selector + '_activate_filters');
55         $("." + id_selector  + "_table_controls").prepend(link);
56         deactivate_filters(id_selector);
57     }
58
59     return table;
60 }
61
62 </script>