From 270ec48a30d181f7b18ce94e34f1397a4542cf58 Mon Sep 17 00:00:00 2001 From: Pedro Amorim Date: Fri, 4 Oct 2024 10:23:55 +0000 Subject: [PATCH] Bug 38071: Preparation Move kohaTable's toggleable clear filter button to its own function --- koha-tmpl/intranet-tmpl/prog/js/datatables.js | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/js/datatables.js b/koha-tmpl/intranet-tmpl/prog/js/datatables.js index 5e319843062..daab5c2c0ed 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/datatables.js +++ b/koha-tmpl/intranet-tmpl/prog/js/datatables.js @@ -56,18 +56,10 @@ var dataTablesDefaults = { "pageLength": 20, "fixedHeader": true, initComplete: function( settings ) { - 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); - }); + $(this).kohaTableToggleClearFilter(settings); if (settings.ajax) { - let table_node = $("#" + tableId); + let table_node = $("#" + settings.nTable.id); if ( typeof this.api === 'function' ) { _dt_add_delay(this.api(), table_node); } else { @@ -1007,4 +999,17 @@ function _dt_add_delay(table_dt, table_node, delay_ms) { return table; }; + $.fn.kohaTableToggleClearFilter = function(settings) { + 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); + }); + } + + })(jQuery); -- 2.43.0