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 var new_parameters = {}
131 $.extend(true, new_parameters, dataTablesDefaults, dt_parameters);
132 var default_column_defs = [
133 { "aTargets": [ "title-string" ], "sType": "title-string" },
134 { "aTargets": [ "string-sort" ], "sType": "string" },
135 { "aTargets": [ "anti-the" ], "sType": "anti-the" },
136 { "aTargets": [ "NoSort" ], "bSortable": false, "bSearchable": false },
138 if ( new_parameters["aoColumnDefs"] === undefined ) {
139 new_parameters["aoColumnDefs"] = default_column_defs;
141 $.extend(true, new_parameters, default_column_defs);
144 table.dataTable(new_parameters);
145 table.DataTable().on("column-visibility.dt", function(){
146 if( typeof columnsInit == 'function' ){
147 // This function can be created separately and used to trigger
148 // an event after the DataTable has loaded AND column visibility
149 // has been updated according to the table's configuration
152 }).columns( hidden_ids ).visible( false );
155 // show a link to activate filtering
158 .attr('id', id_selector + '_activate_filters');
159 $("." + id_selector + "_table_controls").prepend(link);
160 deactivate_filters(id_selector);
163 $(".dt_button_clear_filter, .columns_controls, .export_controls").tooltip();
169 <!-- / columns_settings.inc -->