From c8fef78dc7dbc27dcd739b5eb226e98612eff76d 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) --- 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 819e4854fb8..0d3ce242325 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); @@ -1001,9 +995,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.34.1