From 59b5abd2574fa78ff0863f307e18aaad25475f9f Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 11 Jan 2021 13:36:14 +0100 Subject: [PATCH] Bug 27402: Column filters must AND, not OR Test plan: Use the column filters and the global filter Confirm that the rows are filtered as you expect QA Note: There is more code on top of this, see bug 20212. Signed-off-by: Tomas Cohen Arazi Signed-off-by: Martin Renvoize Signed-off-by: Jonathan Druart --- koha-tmpl/intranet-tmpl/prog/js/datatables.js | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/js/datatables.js b/koha-tmpl/intranet-tmpl/prog/js/datatables.js index a471a5a494..be2da8c976 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/datatables.js +++ b/koha-tmpl/intranet-tmpl/prog/js/datatables.js @@ -564,19 +564,34 @@ jQuery.fn.dataTable.ext.errMode = function(settings, note, message) { }; var filter = data.search.value; - var query_parameters = settings.aoColumns + // Build query for each column filter + var and_query_parameters = settings.aoColumns .filter(function(col) { - return col.bSearchable && typeof col.data == 'string' && (data.columns[col.idx].search.value != '' || filter != '') + return col.bSearchable && typeof col.data == 'string' && data.columns[col.idx].search.value != '' }) .map(function(col) { var part = {}; - var value = data.columns[col.idx].search.value != '' ? data.columns[col.idx].search.value : filter; + var value = data.columns[col.idx].search.value; part[!col.data.includes('.')?'me.'+col.data:col.data] = options.criteria === 'exact'?value:{like: (['contains', 'ends_with'].indexOf(options.criteria) !== -1?'%':'')+value+(['contains', 'starts_with'].indexOf(options.criteria) !== -1?'%':'')}; return part; }); + // Build query for the global search filter + var or_query_parameters = settings.aoColumns + .filter(function(col) { + return col.bSearchable && typeof col.data == 'string' && data.columns[col.idx].search.value == '' && filter != '' + }) + .map(function(col) { + var part = {}; + value = filter; + part[!col.data.includes('.')?'me.'+col.data:col.data] = options.criteria === 'exact'?value:{like: (['contains', 'ends_with'].indexOf(options.criteria) !== -1?'%':'')+value+(['contains', 'starts_with'].indexOf(options.criteria) !== -1?'%':'')}; + return part; + }); + + query_parameters = and_query_parameters; + query_parameters.push(or_query_parameters); if(query_parameters.length) { - query_parameters = JSON.stringify(query_parameters.length === 1?query_parameters[0]:query_parameters); + query_parameters = JSON.stringify(query_parameters.length === 1?query_parameters[0]:{"-and": query_parameters}); if(options.header_filter) { options.query_parameters = query_parameters; } else { -- 2.39.5