From 01d94090c7243adf773f32c94f959acabd8d2298 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. Signed-off-by: David Nind Signed-off-by: Brendan Lawlor Signed-off-by: Lucas Gass (cherry picked from commit 825172c9f24859b94ee448635ce6653e55df8748) Signed-off-by: Paul Derscheid --- .../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 1dbf4758f0..11b3fc298d 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/itemsearch.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/itemsearch.tt @@ -466,7 +466,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 ); @@ -554,7 +554,7 @@ + ' ' + _("Clear") + '' + ' ' + ' ' - + ' ' + + '
' + ' ' + tr + '' + ' ' + ' ' @@ -664,7 +664,7 @@ }; var table_settings = [% TablesSettings.GetTableSettings( 'catalogue', 'itemsearch', 'results', 'json' ) | $raw %]; - $('#results').kohaTable( { + $('#item_search').kohaTable( { "bKohaColumnsUseNames": true, "destroy": true, "serverSide": true, @@ -719,7 +719,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(); }); @@ -767,7 +767,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(); } @@ -776,7 +776,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(); } @@ -785,12 +785,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") ){ @@ -860,7 +860,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 3d10338618..b20813f4d9 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/datatables.js +++ b/koha-tmpl/intranet-tmpl/prog/js/datatables.js @@ -1034,10 +1034,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 = $( `` );