|
Lines 19-36
function KohaTable(selector, dt_parameters, columns_settings) {
Link Here
|
| 19 |
} |
19 |
} |
| 20 |
id++; |
20 |
id++; |
| 21 |
}); |
21 |
}); |
|
|
22 |
|
| 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"]; |
| 28 |
} |
| 29 |
// Data which has the "noExport" class should not appear in print or export |
| 30 |
var export_format = { |
| 31 |
body: function ( data, row, column, node ) { |
| 32 |
var newnode = $(node); |
| 33 |
|
| 34 |
if ( newnode.find(".noExport").length > 0 ) { |
| 35 |
newnode = newnode.clone(); |
| 36 |
newnode.find(".noExport").remove(); |
| 37 |
} |
| 38 |
|
| 39 |
return newnode.text().replace( /\n/g, ' ' ).trim(); |
| 40 |
} |
| 41 |
} |
| 42 |
|
| 43 |
// Add a "Clear filter" button to table filter form field |
| 22 |
dt_parameters[ "buttons" ] = [ |
44 |
dt_parameters[ "buttons" ] = [ |
| 23 |
{ |
45 |
{ |
| 24 |
extend: 'colvis', |
46 |
fade: 100, |
| 25 |
columns: included_ids, |
47 |
className: "dt_button_clear_filter", |
| 26 |
text: _("Column visibility"), |
48 |
titleAttr: _("Clear filter"), |
|
|
49 |
enabled: false, |
| 50 |
text: '<i class="fa fa-lg fa-remove"></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"); |
| 54 |
} |
| 55 |
}, |
| 56 |
{ |
| 57 |
extend: 'csvHtml5', |
| 58 |
text: _("CSV"), |
| 59 |
exportOptions: { |
| 60 |
columns: exportColumns, |
| 61 |
format: export_format |
| 62 |
}, |
| 63 |
}, |
| 64 |
{ |
| 65 |
extend: 'copyHtml5', |
| 66 |
text: _("Copy"), |
| 67 |
exportOptions: { |
| 68 |
columns: exportColumns, |
| 69 |
format: export_format |
| 70 |
}, |
| 71 |
}, |
| 72 |
{ |
| 73 |
extend: 'print', |
| 74 |
text: _("Print"), |
| 75 |
exportOptions: { |
| 76 |
columns: exportColumns, |
| 77 |
format: export_format |
| 78 |
}, |
| 27 |
} |
79 |
} |
| 28 |
]; |
80 |
]; |
| 29 |
var table = $(selector).dataTable($.extend(true, {}, dataTablesDefaults, dt_parameters)); |
|
|
| 30 |
|
81 |
|
| 31 |
$(hidden_ids).each(function(index, value) { |
82 |
if( included_ids.length > 0 ){ |
| 32 |
table.fnSetColumnVis( value, false ); |
83 |
dt_parameters[ "buttons" ].push( |
| 33 |
}); |
84 |
{ |
|
|
85 |
extend: 'colvis', |
| 86 |
fade: 100, |
| 87 |
columns: included_ids, |
| 88 |
className: "columns_controls", |
| 89 |
titleAttr: _("Columns settings"), |
| 90 |
text: '<i class="fa fa-lg fa-gear"></i> <span class="dt-button-text">' + _("Columns") + '</span>', |
| 91 |
exportOptions: { |
| 92 |
columns: exportColumns |
| 93 |
} |
| 94 |
} |
| 95 |
); |
| 96 |
} |
| 97 |
|
| 98 |
var table = $(selector); |
| 99 |
var new_parameters = {} |
| 100 |
$.extend(true, new_parameters, dataTablesDefaults, dt_parameters); |
| 101 |
var default_column_defs = [ |
| 102 |
{ "aTargets": ["title-string"], "sType": "title-string" }, |
| 103 |
{ "aTargets": ["string-sort"], "sType": "string" }, |
| 104 |
{ "aTargets": ["anti-the"], "sType": "anti-the" }, |
| 105 |
{ "aTargets": ["NoSort"], "bSortable": false, "bSearchable": false }, |
| 106 |
]; |
| 107 |
if (new_parameters["aoColumnDefs"] === undefined) { |
| 108 |
new_parameters["aoColumnDefs"] = default_column_defs; |
| 109 |
} else { |
| 110 |
$.extend(true, new_parameters, default_column_defs); |
| 111 |
} |
| 112 |
|
| 113 |
table.dataTable(new_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 |
| 119 |
columnsInit(); |
| 120 |
} |
| 121 |
}).columns(hidden_ids).visible(false); |
| 122 |
|
| 123 |
$(".dt_button_clear_filter, .columns_controls, .export_controls").tooltip(); |
| 34 |
|
124 |
|
| 35 |
return table; |
125 |
return table; |
| 36 |
} |
126 |
} |