Bugzilla – Attachment 145094 Details for
Bug 32559
Support formatted date for column filtering (DT)
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 32559: Add support for formatted date when filtering on a column
Bug-32559-Add-support-for-formatted-date-when-filt.patch (text/plain), 5.21 KB, created by
Kyle M Hall
on 2023-01-06 19:17:52 UTC
(
hide
)
Description:
Bug 32559: Add support for formatted date when filtering on a column
Filename:
MIME Type:
Creator:
Kyle M Hall
Created:
2023-01-06 19:17:52 UTC
Size:
5.21 KB
patch
obsolete
>From 011e421283598b0db0a0b0aefec02793d4309e13 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Tue, 3 Jan 2023 18:00:13 +0100 >Subject: [PATCH] Bug 32559: Add support for formatted date when filtering on a > column > >When dates are displayed formatted (following the dateformat syspref) >in a DataTable table and that there is a filter for the column, we should >filter correctly the data. > >Test plan: >Assuming dateformat is set to metric >Go to the main patron search, search for all patrons (don't provide a >search term) >In the "date of birth" column filter, enter "1958", notice that you see >Henry >Search using an iso formatted date 1958-05-30 >Search using a metric formatted date 30/05/1958 > >Note that: >- it's also working for "Expires on" on the same table. We may want to >adjust other tables that are using the DT REST API wrapper and the >column filters >- You need to search for the full formatted date to make it work. >"30/05" won't work. > >Signed-off-by: Lucas Gass <lucas@bywatersolutions.com> > >Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> >--- > .../prog/en/includes/patron-search.inc | 4 +-- > koha-tmpl/intranet-tmpl/prog/js/datatables.js | 25 ++++++++++++++++--- > 2 files changed, 24 insertions(+), 5 deletions(-) > >diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc >index b5794d02e6..7350fdbce4 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc >@@ -150,14 +150,14 @@ > [% SWITCH column %] > [% CASE 'checkbox' %]<th class="noExport"></th> > [% CASE 'cardnumber' %]<th>Card</th> >- [% CASE 'dateofbirth' %]<th>Date of birth</th> >+ [% CASE 'dateofbirth' %]<th data-datatype="date">Date of birth</th> > [% CASE 'name' %]<th>Name</th> > [% CASE 'name-address' %]<th>Name</th> > [% CASE 'address' %]<th>Address</th> > [% CASE 'address-library' %]<th>Address</th> > [% CASE 'branch' %]<th data-filter="libraries">Library</th> > [% CASE 'category' %]<th data-filter="categories">Category</th> >- [% CASE 'dateexpiry' %]<th>Expires on</td> >+ [% CASE 'dateexpiry' %]<th data-datatype="date">Expires on</td> > [% CASE 'borrowernotes' %]<th>Notes</th> > [% CASE 'phone' %]<th>Phone</th> > [% CASE 'checkouts' %]<th>Checkouts</th> >diff --git a/koha-tmpl/intranet-tmpl/prog/js/datatables.js b/koha-tmpl/intranet-tmpl/prog/js/datatables.js >index 0fbb9b625c..2a6e45144a 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/datatables.js >+++ b/koha-tmpl/intranet-tmpl/prog/js/datatables.js >@@ -597,9 +597,28 @@ jQuery.fn.dataTable.ext.errMode = function(settings, note, message) { > // escape SQL LIKE special characters % and _ > value = value.replace(/(\%|\\)/g, "\\$1"); > } >- part[!attr.includes('.')?'me.'+attr:attr] = criteria === 'exact' >- ? value >- : {like: (['contains', 'ends_with'].indexOf(criteria) !== -1?'%':'') + value + (['contains', 'starts_with'].indexOf(criteria) !== -1?'%':'')}; >+ >+ let built_value; >+ if ( col.datatype !== undefined ) { >+ if ( col.datatype == 'date' ) { >+ let rfc3339 = $date_to_rfc3339(value); >+ if ( rfc3339 != 'Invalid Date' ) { >+ built_value = rfc3339; >+ } >+ } else { >+ console.log("datatype %s not supported yet".format(col.datatype)); >+ } >+ } >+ >+ let value_part; >+ if ( criteria === 'exact' ) { >+ value_part = built_value ? [value, built_value] : value >+ } else { >+ let like = {like: (['contains', 'ends_with'].indexOf(criteria) !== -1?'%':'') + value + (['contains', 'starts_with'].indexOf(criteria) !== -1?'%':'')}; >+ value_part = built_value ? [like, built_value] : like; >+ } >+ >+ part[!attr.includes('.')?'me.'+attr:attr] = value_part; > parts.push(part); > } > return parts; >-- >2.30.2
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 32559
:
144951
|
144954
|
144977
|
145094
|
145095
|
145136
|
153845
|
153846
|
153847