Bug 9573: Lost items report - add KohaTable to itemlost
[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     ];
30
31     var table = $(selector);
32     if ( add_filters ) {
33         // Duplicate the table header row for columnFilter
34         thead_row = table.find('thead tr');
35         clone = thead_row.clone().addClass('filters_row');
36         clone.find("th.NoSort").html('');
37         thead_row.before(clone);
38     }
39
40     table.dataTable($.extend(true, {}, dataTablesDefaults, dt_parameters));
41
42     $(hidden_ids).each(function(index, value) {
43         table.fnSetColumnVis( value, false );
44     });
45
46     if ( add_filters ) {
47         // show a link to activate filtering
48         link = $('<a>')
49             .attr('href', '#')
50             .attr('id', id_selector + '_activate_filters');
51         $("." + id_selector  + "_table_controls").prepend(link);
52         deactivate_filters(id_selector);
53     }
54
55     return table;
56 }
57
58 </script>