From 7ecd26e4bb926315b4b49709fde6a62ce3804bf5 Mon Sep 17 00:00:00 2001 From: Owen Leonard Date: Wed, 27 Jan 2021 11:48:47 +0000 Subject: [PATCH] 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 Signed-off-by: Martin Renvoize Signed-off-by: Jonathan Druart --- .../en/includes/columns_settings.inc | 104 ++++++++++++++++-- .../en/modules/opac-readingrecord.tt | 18 ++- 2 files changed, 104 insertions(+), 18 deletions(-) diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/columns_settings.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/columns_settings.inc index 97f201be30..2e702e1678 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/columns_settings.inc +++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/columns_settings.inc @@ -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: ' ' + _("Clear filter") + '', + 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: ' ' + _("Columns") + '', + 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; } diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-readingrecord.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-readingrecord.tt index 5cabd8f6a6..668e8680b9 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-readingrecord.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-readingrecord.tt @@ -1,6 +1,7 @@ [% USE raw %] [% USE Koha %] [% USE KohaDates %] +[% USE TablesSettings %] [% INCLUDE 'doc-head-open.inc' %] [% IF ( LibraryNameTitle ) %][% LibraryNameTitle | html %][% ELSE %]Koha online[% END %] catalog › Your checkout history [% INCLUDE 'doc-head-close.inc' %] @@ -85,8 +86,8 @@ - - + + @@ -202,6 +203,7 @@ [% INCLUDE 'opac-bottom.inc' %] [% BLOCK jsinclude %] [% INCLUDE 'datatables.inc' %] +[% INCLUDE 'columns_settings.inc' %]
Type Title Item type Call no.