From 39e54ee842d33dade7a31e397ee4558073ce5ff0 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 --- 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 5e319843062..25a4bda3899 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.46.2