Bug 32030: ERM - Vue - Datatables fix (follow-up 2)

The column visibility broke the tr filters

Signed-off-by: Jonathan Field <jonathan.field@ptfs-europe.com>

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Jonathan Druart 2022-05-03 09:39:06 +02:00 committed by Tomas Cohen Arazi
parent 97494015cd
commit 45360cd696
Signed by: tomascohen
GPG key ID: 0A272EA1B2F3C15F

View file

@ -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