@@ -, +, @@ export --- .../en/includes/columns_settings.inc | 104 ++++++++++++++++-- .../en/modules/opac-readingrecord.tt | 18 ++- 2 files changed, 104 insertions(+), 18 deletions(-) --- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/columns_settings.inc +++ a/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; } --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-readingrecord.tt +++ a/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.