1 [% USE TablesSettings %]
4 function KohaTable(selector, dt_parameters, columns_settings) {
8 $(columns_settings).each( function() {
9 var named_id = $( 'thead th[data-colname="' + this.columnname + '"]', selector ).index( selector+' th' );
11 var used_id = dt_parameters.bKohaColumnsUseNames ? named_id : id;
12 if ( used_id == -1 ) return;
14 if ( this['is_hidden'] == "1" ) {
15 hidden_ids.push( used_id );
17 if ( this['cannot_be_toggled'] == "0" ) {
18 included_ids.push( used_id );
23 // By default we include all visible columns in exports and print unless they have the "noExport" class
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"];
29 // Data which has the "noExport" class should not appear in print or export
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 // Add a "Clear filter" button to table filter form field
44 dt_parameters[ "buttons" ] = [
47 className: "dt_button_clear_filter",
48 titleAttr: _("Clear filter"),
50 text: '<i class="fa fa-lg fa-remove" aria-hidden="true"></i> <span class="dt-button-text">' + _("Clear filter") + '</span>',
51 action: function ( e, dt, node, config ) {
52 dt.search( "" ).draw("page");
53 node.addClass("disabled");
60 columns: exportColumns,
68 columns: exportColumns,
76 columns: exportColumns,
82 if( included_ids.length > 0 ){
83 dt_parameters[ "buttons" ].push(
87 columns: included_ids,
88 className: "columns_controls",
89 titleAttr: _("Columns settings"),
90 text: '<i class="fa fa-lg fa-gear" aria-hidden="true"></i> <span class="dt-button-text">' + _("Columns") + '</span>',
92 columns: exportColumns
98 var table = $(selector);
99 var new_parameters = {}
100 $.extend(true, new_parameters, dataTablesDefaults, dt_parameters);
101 var default_column_defs = [
102 { "aTargets": ["string-sort"], "sType": "string" },
103 { "aTargets": ["anti-the"], "sType": "anti-the" },
104 { "aTargets": ["NoSort"], "bSortable": false, "bSearchable": false }
106 if (new_parameters["aoColumnDefs"] === undefined) {
107 new_parameters["aoColumnDefs"] = default_column_defs;
109 $.extend(true, new_parameters, default_column_defs);
112 table.dataTable(new_parameters);
113 table.DataTable().on("column-visibility.dt", function () {
114 if (typeof columnsInit == 'function') {
115 // This function can be created separately and used to trigger
116 // an event after the DataTable has loaded AND column visibility
117 // has been updated according to the table's configuration
120 }).columns(hidden_ids).visible(false);
122 $(".dt_button_clear_filter, .columns_controls, .export_controls").tooltip();