From 45360cd69602a26716b4fa2bacf486542ad97181 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 3 May 2022 09:39:06 +0200 Subject: [PATCH] Bug 32030: ERM - Vue - Datatables fix (follow-up 2) The column visibility broke the tr filters Signed-off-by: Jonathan Field Signed-off-by: Martin Renvoize Signed-off-by: Kyle M Hall Signed-off-by: Tomas Cohen Arazi --- koha-tmpl/intranet-tmpl/prog/js/datatables.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/koha-tmpl/intranet-tmpl/prog/js/datatables.js b/koha-tmpl/intranet-tmpl/prog/js/datatables.js index 2f55420eb0..3d49bdd55a 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/datatables.js +++ b/koha-tmpl/intranet-tmpl/prog/js/datatables.js @@ -854,6 +854,7 @@ jQuery.fn.dataTable.ext.errMode = function(settings, note, message) { $(this).find('thead tr:eq(1) th').each( function (i) { var is_searchable = table_dt.settings()[0].aoColumns[i].bSearchable; $(this).removeClass('sorting'); + $(this).data('th-id', i); if ( is_searchable ) { let input_type = 'input'; if ( $(this).data('filter') ) { @@ -904,6 +905,18 @@ jQuery.fn.dataTable.ext.errMode = function(settings, note, message) { } table.DataTable().on("column-visibility.dt", function(){ + if ( add_filters ) { + let visible_columns = table_dt.columns().visible(); + $(table).find('thead tr:eq(1) th').each( function (i) { + let th_id = $(this).data('th-id'); + if ( visible_columns[th_id] == false ) { + $(this).hide(); + } else { + $(this).show(); + } + }); + } + if( typeof columnsInit == 'function' ){ // This function can be created separately and used to trigger // an event after the DataTable has loaded AND column visibility