1 [% USE ColumnsSettings %]
2 <!-- columns_settings.inc -->
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( selector + ' 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"];
31 body: function ( data, row, column, node ) {
32 var newnode = $(node);
34 if ( newnode.find(".noExport").length > 0 ) {
35 newnode = newnode.clone();
36 newnode.find(".noExport").remove();
39 return newnode.text().replace( /\n/g, ' ' ).trim();
43 var export_buttons = [
48 columns: exportColumns,
56 columns: exportColumns,
64 columns: exportColumns,
72 columns: exportColumns,
78 dt_parameters[ "buttons" ] = [
81 className: "dt_button_clear_filter",
82 titleAttr: _("Clear filter"),
84 text: '<i class="fa fa-lg fa-remove"></i> <span class="dt-button-text">' + _("Clear filter") + '</span>',
85 action: function ( e, dt, node, config ) {
86 dt.search( "" ).draw("page");
87 node.addClass("disabled");
92 if( included_ids.length > 0 ){
93 dt_parameters[ "buttons" ].push(
97 columns: included_ids,
98 className: "columns_controls",
99 titleAttr: _("Columns settings"),
100 text: '<i class="fa fa-lg fa-gear"></i> <span class="dt-button-text">' + _("Columns") + '</span>',
102 columns: exportColumns
108 dt_parameters[ "buttons" ].push(
110 extend: 'collection',
113 className: "export_controls",
114 titleAttr: _("Export or print"),
115 text: '<i class="fa fa-lg fa-download"></i> <span class="dt-button-text">' + _("Export") + '</span>',
116 buttons: export_buttons
120 var table = $(selector);
122 // Duplicate the table header row for columnFilter
123 thead_row = table.find('thead tr');
124 clone = thead_row.clone().addClass('filters_row');
125 clone.find("th.NoSort").html('');
126 thead_row.before(clone);
129 table.dataTable($.extend(true, {}, dataTablesDefaults, dt_parameters));
131 table.DataTable().on("column-visibility.dt", function(){
132 if( typeof columnsInit == 'function' ){
133 // This function can be created separately and used to trigger
134 // an event after the DataTable has loaded AND column visibility
135 // has been updated according to the table's configuration
138 }).columns( hidden_ids ).visible( false );
141 // show a link to activate filtering
144 .attr('id', id_selector + '_activate_filters');
145 $("." + id_selector + "_table_controls").prepend(link);
146 deactivate_filters(id_selector);
149 $(".dt_button_clear_filter, .columns_controls, .export_controls").tooltip();
155 <!-- / columns_settings.inc -->