1 [% USE ColumnsSettings %]
4 function KohaTable(id_selector, dt_parameters, columns_settings, add_filters) {
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 );
18 if ( this['cannot_be_toggled'] == "0" ) {
19 included_ids.push( used_id );
24 var exportColumns = ":visible:not(.noExport)";
25 if( dt_parameters.hasOwnProperty("exportColumns") ){
26 // A custom buttons configuration has been passed from the page
27 exportColumns = dt_parameters["exportColumns"];
30 var export_buttons = [
35 columns: exportColumns
42 columns: exportColumns
49 columns: exportColumns
56 columns: exportColumns
61 dt_parameters[ "buttons" ] = [
64 className: "dt_button_clear_filter",
65 titleAttr: _("Clear filter"),
67 text: '<i class="fa fa-lg fa-remove"></i> <span class="dt-button-text">' + _("Clear filter") + '</span>',
68 action: function ( e, dt, node, config ) {
69 dt.search( "" ).draw("page");
70 node.addClass("disabled");
75 if( included_ids.length > 0 ){
76 dt_parameters[ "buttons" ].push(
80 columns: included_ids,
81 className: "columns_controls",
82 titleAttr: _("Columns settings"),
83 text: '<i class="fa fa-lg fa-gear"></i> <span class="dt-button-text">' + _("Columns") + '</span>',
85 columns: exportColumns
91 dt_parameters[ "buttons" ].push(
96 className: "export_controls",
97 titleAttr: _("Export or print"),
98 text: '<i class="fa fa-lg fa-download"></i> <span class="dt-button-text">' + _("Export") + '</span>',
99 buttons: export_buttons
103 var table = $(selector);
105 // Duplicate the table header row for columnFilter
106 thead_row = table.find('thead tr');
107 clone = thead_row.clone().addClass('filters_row');
108 clone.find("th.NoSort").html('');
109 thead_row.before(clone);
112 table.dataTable($.extend(true, {}, dataTablesDefaults, dt_parameters));
114 table.DataTable().on("column-visibility.dt", function(){
115 if( typeof columnsInit == 'function' ){
116 // This function can be created separately and used to trigger
117 // an event after the DataTable has loaded AND column visibility
118 // has been updated according to the table's configuration
121 }).columns( hidden_ids ).visible( false );
124 // show a link to activate filtering
127 .attr('id', id_selector + '_activate_filters');
128 $("." + id_selector + "_table_controls").prepend(link);
129 deactivate_filters(id_selector);
132 $(".dt_button_clear_filter, .columns_controls, .export_controls").tooltip();