Bug 27005: (follow-up) Enable the exclusion of columns from export

This patch copies code from the staff interface which allows us to add a
class to table columns which should not be included in print or export
operations. The hidden column which facilitates the "Checkouts" and
"On-site checkouts" tabs can now be hidden in prints and exports.

To test, apply the patch and follow the previous test plan. When testing
the export and print buttons, confirm that the column with
"standard_checkout" data is not included.

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Owen Leonard 2021-01-27 11:48:47 +00:00 committed by Jonathan Druart
parent ebc20ffef4
commit 7ecd26e4bb
2 changed files with 104 additions and 18 deletions

View file

@ -19,18 +19,108 @@ function KohaTable(selector, dt_parameters, columns_settings) {
}
id++;
});
// By default we include all visible columns in exports and print unless they have the "noExport" class
var exportColumns = ":visible:not(.noExport)";
if( dt_parameters.hasOwnProperty("exportColumns") ){
// A custom buttons configuration has been passed from the page
exportColumns = dt_parameters["exportColumns"];
}
// Data which has the "noExport" class should not appear in print or export
var export_format = {
body: function ( data, row, column, node ) {
var newnode = $(node);
if ( newnode.find(".noExport").length > 0 ) {
newnode = newnode.clone();
newnode.find(".noExport").remove();
}
return newnode.text().replace( /\n/g, ' ' ).trim();
}
}
// Add a "Clear filter" button to table filter form field
dt_parameters[ "buttons" ] = [
{
extend: 'colvis',
columns: included_ids,
text: _("Column visibility"),
fade: 100,
className: "dt_button_clear_filter",
titleAttr: _("Clear filter"),
enabled: false,
text: '<i class="fa fa-lg fa-remove"></i> <span class="dt-button-text">' + _("Clear filter") + '</span>',
action: function ( e, dt, node, config ) {
dt.search( "" ).draw("page");
node.addClass("disabled");
}
},
{
extend: 'csvHtml5',
text: _("CSV"),
exportOptions: {
columns: exportColumns,
format: export_format
},
},
{
extend: 'copyHtml5',
text: _("Copy"),
exportOptions: {
columns: exportColumns,
format: export_format
},
},
{
extend: 'print',
text: _("Print"),
exportOptions: {
columns: exportColumns,
format: export_format
},
}
];
var table = $(selector).dataTable($.extend(true, {}, dataTablesDefaults, dt_parameters));
$(hidden_ids).each(function(index, value) {
table.fnSetColumnVis( value, false );
});
if( included_ids.length > 0 ){
dt_parameters[ "buttons" ].push(
{
extend: 'colvis',
fade: 100,
columns: included_ids,
className: "columns_controls",
titleAttr: _("Columns settings"),
text: '<i class="fa fa-lg fa-gear"></i> <span class="dt-button-text">' + _("Columns") + '</span>',
exportOptions: {
columns: exportColumns
}
}
);
}
var table = $(selector);
var new_parameters = {}
$.extend(true, new_parameters, dataTablesDefaults, dt_parameters);
var default_column_defs = [
{ "aTargets": ["title-string"], "sType": "title-string" },
{ "aTargets": ["string-sort"], "sType": "string" },
{ "aTargets": ["anti-the"], "sType": "anti-the" },
{ "aTargets": ["NoSort"], "bSortable": false, "bSearchable": false },
];
if (new_parameters["aoColumnDefs"] === undefined) {
new_parameters["aoColumnDefs"] = default_column_defs;
} else {
$.extend(true, new_parameters, default_column_defs);
}
table.dataTable(new_parameters);
table.DataTable().on("column-visibility.dt", function () {
if (typeof columnsInit == 'function') {
// This function can be created separately and used to trigger
// an event after the DataTable has loaded AND column visibility
// has been updated according to the table's configuration
columnsInit();
}
}).columns(hidden_ids).visible(false);
$(".dt_button_clear_filter, .columns_controls, .export_controls").tooltip();
return table;
}

View file

@ -1,6 +1,7 @@
[% USE raw %]
[% USE Koha %]
[% USE KohaDates %]
[% USE TablesSettings %]
[% INCLUDE 'doc-head-open.inc' %]
<title>[% IF ( LibraryNameTitle ) %][% LibraryNameTitle | html %][% ELSE %]Koha online[% END %] catalog &rsaquo; Your checkout history</title>
[% INCLUDE 'doc-head-close.inc' %]
@ -85,8 +86,8 @@
<table id="readingrec" class="table table-bordered table-striped">
<thead>
<tr>
<th style="display:none;">Type</th>
<th class="nosort"></th>
<th style="display:none;" class="noExport">Type</th>
<th class="NoSort noExport"></th>
<th class="anti-the">Title</th>
<th>Item type</th>
<th>Call no.</th>
@ -202,6 +203,7 @@
[% INCLUDE 'opac-bottom.inc' %]
[% BLOCK jsinclude %]
[% INCLUDE 'datatables.inc' %]
[% INCLUDE 'columns_settings.inc' %]
<script>
$(document).ready(function(){
[% IF ( GoogleJackets ) %]KOHA.Google.GetCoverFromIsbn();[% END %]
@ -209,21 +211,15 @@
$('#sortform').submit();
});
var table = $("#readingrec").dataTable($.extend(true, {}, dataTablesDefaults, {
var columns_settings = []; // Empty because there are no columns we want to be configurable
var table = KohaTable("#readingrec", {
"dom": '<"top"<"table_entries"i><"table_controls"fB>>t',
"sorting": [[ 1, "asc" ]],
"autoWidth": false,
"columnDefs": [
{ "targets": [ "nosort" ],"sortable": false,"searchable": false },
{ "type": "anti-the", "targets" : [ "anti-the" ] },
{ "type": "title-string", "targets" : [ "title-string" ] }
],
"language": {
"search": "_INPUT_",
"searchPlaceholder": _("Search")
}
}));
}, columns_settings);
var tabs = $("#tabs").tabs({
activate: function(e, ui) {