From c301ae8757d7c16ce5f1a99de8d6cd479e4b9544 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 31 Jul 2025 15:00:01 +0200 Subject: [PATCH] Bug 40565: Fix column filters on item search The item search table is different from the other tables. It is using server-side but its own way (not using the REST API). Test plan: Search items and filter using the column filters: collections, library, item types, AVs, etc. QA: I am not very happy with this patch but, feel free to suggest a better fix! Note that "results" was too generic and it felt better to adjust it. --- .../prog/en/modules/catalogue/itemsearch.tt | 18 +++++++++--------- koha-tmpl/intranet-tmpl/prog/js/datatables.js | 13 +++++++++---- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/itemsearch.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/itemsearch.tt index a050fdf52e7..8cdc7597911 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/itemsearch.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/itemsearch.tt @@ -446,7 +446,7 @@ let item_search_selections = JSON.parse( localStorage.getItem("item_search_selections") ) || []; if( item_search_selections.length > 0 ){ showItemSelections( item_search_selections.length ); - $("#results input[type='checkbox']").each(function(){ + $("#item_search input[type='checkbox']").each(function(){ var itemnumber = $(this).val(); if( item_search_selections.indexOf( itemnumber ) >= 0 ){ $(this).prop("checked", true ); @@ -534,7 +534,7 @@ + ' ' + _("Clear") + '' + ' ' + ' ' - + ' ' + + '
' + ' ' + tr + '' + ' ' + ' ' @@ -644,7 +644,7 @@ }; var table_settings = [% TablesSettings.GetTableSettings( 'catalogue', 'itemsearch', 'results', 'json' ) | $raw %]; - $('#results').kohaTable( { + $('#item_search').kohaTable( { "bKohaColumnsUseNames": true, "destroy": true, "serverSide": true, @@ -699,7 +699,7 @@ fixedHeader: false // There is a bug on this view }, table_settings, true, null, filters_options ); - $('#results').on('draw.dt', function (e, settings) { + $('#item_search').on('draw.dt', function (e, settings) { prepSelections(); $('[data-bs-toggle="tooltip"]').tooltip(); }); @@ -747,7 +747,7 @@ $("body").on("click", "#select_all", function(e) { e.preventDefault(); - $("#results input[type='checkbox']").each(function(){ + $("#item_search input[type='checkbox']").each(function(){ if( $(this).prop("checked") == false ){ $(this).prop( "checked", true ).change(); } @@ -756,7 +756,7 @@ $("body").on("click", "#clear_all", function(e) { e.preventDefault(); - $("#results input[type='checkbox']").each(function(){ + $("#item_search input[type='checkbox']").each(function(){ if( $(this).prop("checked") == true ){ $(this).prop( "checked", false ).change(); } @@ -765,12 +765,12 @@ $("body").on("click", "#clear-row-selection", function(e){ e.preventDefault(); - $("#results input[type='checkbox']").prop("checked" ,false ).change(); + $("#item_search input[type='checkbox']").prop("checked" ,false ).change(); localStorage.removeItem("item_search_selections"); showItemSelections( 0 ); }); - $("body").on('change', '#results input[type="checkbox"]', function() { + $("body").on('change', '#item_search input[type="checkbox"]', function() { let item_search_selections = JSON.parse( localStorage.getItem("item_search_selections") ) || []; var itemnumber = $(this).val(); if( $(this).prop("checked") ){ @@ -840,7 +840,7 @@ batch_mod_form.submit(); }); - $("body").on('click','#results tbody td',function(e){ + $("body").on('click','#item_search tbody td',function(e){ var checkbox = $(this).find("input[type=checkbox]"); if (e.target.type != "checkbox") { checkbox.prop('checked', !checkbox.prop("checked")); diff --git a/koha-tmpl/intranet-tmpl/prog/js/datatables.js b/koha-tmpl/intranet-tmpl/prog/js/datatables.js index 28d1cf5eee8..faef829049b 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/datatables.js +++ b/koha-tmpl/intranet-tmpl/prog/js/datatables.js @@ -1062,10 +1062,15 @@ function _dt_add_filters(table_node, table_dt, filters_options = {}) { return this._id !== "" && this._str !== ""; }) .each(function () { - let optionValue = - table_dt.settings()[0].ajax !== null - ? `^${this._id}$` - : this._id; + let optionValue = this._id; + + if ( + table_dt.settings()[0].ajax !== null && + table_node.attr("id") !== "item_search" + ) { + optionValue = `^${this._id}$`; + } + let o = $( `` ); -- 2.34.1