Bugzilla – Attachment 137695 Details for
Bug 29302
The dataTables Koha RESTful API wrapper should allow picking match type at the column level
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 29302: Allow passing of 'criteria' at the column level
Bug-29302-Allow-passing-of-criteria-at-the-column-.patch (text/plain), 5.39 KB, created by
Martin Renvoize (ashimema)
on 2022-07-14 09:14:53 UTC
(
hide
)
Description:
Bug 29302: Allow passing of 'criteria' at the column level
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2022-07-14 09:14:53 UTC
Size:
5.39 KB
patch
obsolete
>From 2f4fd51dbf231e8a0160530593fcd48a01009b67 Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Thu, 21 Oct 2021 18:00:57 +0100 >Subject: [PATCH] Bug 29302: Allow passing of 'criteria' at the column level > >This patch adds the option to pass 'criteria' at the 'column' definition >level which means you can set 'contains', 'starts_with', 'ends_with' and >'exact' match types for each different column. >--- > koha-tmpl/intranet-tmpl/prog/js/datatables.js | 28 ++++++++++--------- > 1 file changed, 15 insertions(+), 13 deletions(-) > >diff --git a/koha-tmpl/intranet-tmpl/prog/js/datatables.js b/koha-tmpl/intranet-tmpl/prog/js/datatables.js >index e2d8547157..aec7f519e5 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/datatables.js >+++ b/koha-tmpl/intranet-tmpl/prog/js/datatables.js >@@ -492,15 +492,17 @@ jQuery.fn.dataTable.ext.errMode = function(settings, note, message) { > > /** > * Create a new dataTables instance that uses the Koha RESTful API's as a data source >- * @param {Object} options Please see the dataTables documentation for further details >- * We extend the options set with the `criteria` key which allows >- * the developer to select the match type to be applied during searches >- * Valid keys are: `contains`, `starts_with`, `ends_with` and `exact` >- * @param {Object} table_settings The arrayref as returned by TableSettings.GetTableSettings function available >- * from the columns_settings template toolkit include >- * @param {Boolean} add_filters Add a filters row as the top row of the table >- * @param {Object} default_filters Add a set of default search filters to apply at table initialisation >- * @return {Object} The dataTables instance >+ * @param {Object} options Please see the dataTables settings documentation for further >+ * details >+ * @param {string} [options.criteria=contains] A koha specific extension to the dataTables settings block that >+ * allows setting the 'comparison operator' used in searches >+ * Supports `contains`, `starts_with`, `ends_with` and `exact` match >+ * @param {string} [options.columns.*.criteria] As above, but at the column definition level >+ * @param {Object} table_settings The arrayref as returned by TableSettings.GetTableSettings function >+ * available from the columns_settings template toolkit include >+ * @param {Boolean} add_filters Add a filters row as the top row of the table >+ * @param {Object} default_filters Add a set of default search filters to apply at table initialisation >+ * @return {Object} The dataTables instance > */ > $.fn.kohaTable = function(options, table_settings, add_filters, default_filters) { > var settings = null; >@@ -570,7 +572,7 @@ jQuery.fn.dataTable.ext.errMode = function(settings, note, message) { > _per_page: length > }; > >- function build_query(col, value){ >+ function build_query(col, value, is_column){ > > // escape SQL special characters > value = value.replace(/(\%|\_|\\)/g, "\\$1" ); >@@ -580,7 +582,7 @@ jQuery.fn.dataTable.ext.errMode = function(settings, note, message) { > for (var i=0;i<attributes.length;i++){ > var part = {}; > var attr = attributes[i]; >- let criteria = options.criteria; >+ let criteria = is_column ? col.criteria || options.criteria : options.criteria; > if ( value.match(/^\^(.*)\$$/) ) { > value = value.replace(/^\^/, '').replace(/\$$/, ''); > criteria = "exact"; >@@ -601,7 +603,7 @@ jQuery.fn.dataTable.ext.errMode = function(settings, note, message) { > }) > .map(function(col) { > var value = data.columns[col.idx].search.value; >- return build_query(col, value) >+ return build_query(col, value, 1) > }) > .map(function r(e){ > return ($.isArray(e) ? $.map(e, r) : e); >@@ -614,7 +616,7 @@ jQuery.fn.dataTable.ext.errMode = function(settings, note, message) { > }) > .map(function(col) { > var value = filter; >- return build_query(col, value) >+ return build_query(col, value, 0) > }) > .map(function r(e){ > return ($.isArray(e) ? $.map(e, r) : e); >-- >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 29302
:
126673
|
127358
| 137695