1 [% USE TablesSettings %]
2 <!-- columns_settings.inc -->
5 function KohaTable(id_selector, dt_parameters, columns_settings, add_filters) {
9 var selector = '#' + id_selector;
11 $(columns_settings).each( function() {
12 var named_id = $( 'thead th[data-colname="' + this.columnname + '"]', selector ).index( selector + ' th' );
13 var used_id = dt_parameters.bKohaColumnsUseNames ? named_id : counter;
14 if ( used_id == -1 ) return;
16 if ( this['is_hidden'] == "1" ) {
17 hidden_ids.push( used_id );
19 if ( this['cannot_be_toggled'] == "0" ) {
20 included_ids.push( used_id );
25 var exportColumns = ":visible:not(.noExport)";
26 if( dt_parameters.hasOwnProperty("exportColumns") ){
27 // A custom buttons configuration has been passed from the page
28 exportColumns = dt_parameters["exportColumns"];
32 body: function ( data, row, column, node ) {
33 var newnode = $(node);
35 if ( newnode.find(".noExport").length > 0 ) {
36 newnode = newnode.clone();
37 newnode.find(".noExport").remove();
40 return newnode.text().replace( /\n/g, ' ' ).trim();
44 var export_buttons = [
49 columns: exportColumns,
57 columns: exportColumns,
65 columns: exportColumns,
73 columns: exportColumns,
79 dt_parameters[ "buttons" ] = [
82 className: "dt_button_clear_filter",
83 titleAttr: _("Clear filter"),
85 text: '<i class="fa fa-lg fa-remove"></i> <span class="dt-button-text">' + _("Clear filter") + '</span>',
86 action: function ( e, dt, node, config ) {
87 dt.search( "" ).draw("page");
88 node.addClass("disabled");
93 if( included_ids.length > 0 ){
94 dt_parameters[ "buttons" ].push(
98 columns: included_ids,
99 className: "columns_controls",
100 titleAttr: _("Columns settings"),
101 text: '<i class="fa fa-lg fa-gear"></i> <span class="dt-button-text">' + _("Columns") + '</span>',
103 columns: exportColumns
109 dt_parameters[ "buttons" ].push(
111 extend: 'collection',
114 className: "export_controls",
115 titleAttr: _("Export or print"),
116 text: '<i class="fa fa-lg fa-download"></i> <span class="dt-button-text">' + _("Export") + '</span>',
117 buttons: export_buttons
121 var table = $(selector);
123 // Duplicate the table header row for columnFilter
124 thead_row = table.find('thead tr');
125 clone = thead_row.clone().addClass('filters_row');
126 clone.find("th.NoSort").html('');
127 thead_row.before(clone);
130 table.dataTable($.extend(true, {}, dataTablesDefaults, dt_parameters));
132 table.DataTable().on("column-visibility.dt", function(){
133 if( typeof columnsInit == 'function' ){
134 // This function can be created separately and used to trigger
135 // an event after the DataTable has loaded AND column visibility
136 // has been updated according to the table's configuration
139 }).columns( hidden_ids ).visible( false );
142 // show a link to activate filtering
145 .attr('id', id_selector + '_activate_filters');
146 $("." + id_selector + "_table_controls").prepend(link);
147 deactivate_filters(id_selector);
150 $(".dt_button_clear_filter, .columns_controls, .export_controls").tooltip();
156 <!-- / columns_settings.inc -->