Bugzilla – Attachment 115054 Details for
Bug 27402
Add column filtering to the Datatables REST API wrapper
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 27402: Column filters must AND, not OR
Bug-27402-Column-filters-must-AND-not-OR.patch (text/plain), 3.82 KB, created by
Jonathan Druart
on 2021-01-12 09:21:39 UTC
(
hide
)
Description:
Bug 27402: Column filters must AND, not OR
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2021-01-12 09:21:39 UTC
Size:
3.82 KB
patch
obsolete
>From 23964e23fa30bc2cf6805646e09353c85350609d Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >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. >--- > 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.20.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 27402
:
115051
|
115052
|
115053
|
115054
|
115813
|
115814
|
115815
|
115935
|
115936
|
115937
|
115942
|
115966