From 503f310a14c19a66c11fe6a9b310f57aa912025c Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 7 Oct 2024 10:49:36 +0200 Subject: [PATCH] Bug 38071: Ensure search.dt is triggered I don't really understand why the previous code is not working, but the search.dt event handler is not correctly set when initComplete is passed to the constructor (for instance from the patrons search) Signed-off-by: Pedro Amorim Signed-off-by: Martin Renvoize Signed-off-by: Katrin Fischer --- koha-tmpl/intranet-tmpl/prog/js/datatables.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/js/datatables.js b/koha-tmpl/intranet-tmpl/prog/js/datatables.js index 576a923398..5f5d81a34f 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/datatables.js +++ b/koha-tmpl/intranet-tmpl/prog/js/datatables.js @@ -59,12 +59,6 @@ var dataTablesDefaults = { var tableId = settings.nTable.id var state = settings.oLoadedState; state && toggledClearFilter(state.search.search, tableId); - // When the DataTables search function is triggered, - // enable or disable the "Clear filter" button based on - // the presence of a search string - $(this).on( 'search.dt', function ( e, settings ) { - toggledClearFilter(settings.oPreviousSearch.sSearch, tableId); - }); if (settings.ajax) { let table_node = $("#" + tableId); @@ -999,9 +993,16 @@ function _dt_add_delay(table_dt, table_node, delay_ms) { _dt_add_filters(this, table_dt, filters_options); } - table.DataTable().on("column-visibility.dt", function(){_dt_on_visibility(add_filters, table, table_dt);}) + table_dt.on("column-visibility.dt", function(){_dt_on_visibility(add_filters, table, table_dt);}) .columns( hidden_ids ).visible( false ); + table_dt.on( 'search.dt', function ( e, settings ) { + // When the DataTables search function is triggered, + // enable or disable the "Clear filter" button based on + // the presence of a search string + toggledClearFilter(settings.oPreviousSearch.sSearch, settings.nTable.id); + }); + return table; }; -- 2.39.5