From 94ba5b5873dc369190b459c0e37c4e0e9ed3461f Mon Sep 17 00:00:00 2001 From: Allan Jardine Date: Tue, 25 Jul 2023 19:46:31 +0000 Subject: [PATCH 1/3] Fix: Natural sorting nono-standard methods were not reverse sorting --- sorting/natural.js | 4 ++-- sorting/natural.min.js | 2 +- sorting/natural.min.mjs | 2 +- sorting/natural.mjs | 4 ++-- sorting/src/natural.ts | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/sorting/natural.js b/sorting/natural.js index 50d47aa..57d003f 100644 --- a/sorting/natural.js +++ b/sorting/natural.js @@ -147,7 +147,7 @@ DataTable.ext.type.order['natural-desc'] = function (a, b) { DataTable.ext.type.order['natural-nohtml-asc'] = function (a, b) { return naturalSort(a, b, false); }; -DataTable.ext.type.order['natural-nohtml-asc'] = function (a, b) { +DataTable.ext.type.order['natural-nohtml-desc'] = function (a, b) { return naturalSort(a, b, false) * -1; }; DataTable.ext.type.order['natural-ci-asc'] = function (a, b) { @@ -155,7 +155,7 @@ DataTable.ext.type.order['natural-ci-asc'] = function (a, b) { b = b.toString().toLowerCase(); return naturalSort(a, b, true); }; -DataTable.ext.type.order['natural-ci-asc'] = function (a, b) { +DataTable.ext.type.order['natural-ci-desc'] = function (a, b) { a = a.toString().toLowerCase(); b = b.toString().toLowerCase(); return naturalSort(a, b, true) * -1; diff --git a/sorting/natural.min.js b/sorting/natural.min.js index a91a3fa..3801415 100644 --- a/sorting/natural.min.js +++ b/sorting/natural.min.js @@ -1,2 +1,2 @@ /*! © SpryMedia Ltd, Jim Palmer, Michael Buehler, Mike Grier, Clint Priest, Kyle Adams, guillermo - datatables.net/license */ -!function(r){var n,a;"function"==typeof define&&define.amd?define(["jquery","datatables.net"],function(e){return r(e,window,document)}):"object"==typeof exports?(n=require("jquery"),a=function(e,t){t.fn.dataTable||require("datatables.net")(e,t)},"undefined"==typeof window?module.exports=function(e,t){return e=e||window,t=t||n(e),a(e,t),r(t,0,e.document)}:(a(window,n),module.exports=r(n,window,window.document))):r(jQuery,window,document)}(function(e,t,r,n){"use strict";e=e.fn.dataTable;function a(e,t,r){var n=/(^-?[0-9]+(\.?[0-9]*)[df]?e?[0-9]?%?$|^0x[0-9a-f]+$|[0-9]+)/gi,a=/(^[ ]*|[ ]*$)/g,o=/(^([\w ]+,?[\w ]+)?[\w ]+,?[\w ]+\d+:\d+(:\d+)?[\w ]?|^\d{1,4}[\/\-]\d{1,4}[\/\-]\d{1,4}|^\w+, \w+ \d+, \d{4})/,i=/^0x[0-9a-f]+$/i,u=/^0/,c=/(<([^>]+)>)/gi,e=e.toString().replace(a,"")||"",t=t.toString().replace(a,"")||"",d=(r||(e=e.replace(c,""),t=t.replace(c,"")),e.replace(n,"\0$1\0").replace(/\0$/,"").replace(/^\0/,"").split("\0")),f=t.replace(n,"\0$1\0").replace(/\0$/,"").replace(/^\0/,"").split("\0"),a=parseInt(e.match(i),10)||1!==d.length&&e.match(o)&&Date.parse(e),r=parseInt(t.match(i),10)||a&&t.match(o)&&Date.parse(t)||null;if(r){if(a]+)>)/gi,e=e.toString().replace(a,"")||"",t=t.toString().replace(a,"")||"",d=(r||(e=e.replace(c,""),t=t.replace(c,"")),e.replace(n,"\0$1\0").replace(/\0$/,"").replace(/^\0/,"").split("\0")),f=t.replace(n,"\0$1\0").replace(/\0$/,"").replace(/^\0/,"").split("\0"),a=parseInt(e.match(i),10)||1!==d.length&&e.match(o)&&Date.parse(e),r=parseInt(t.match(i),10)||a&&t.match(o)&&Date.parse(t)||null;if(r){if(a]+)>)/gi,t=t.toString().replace(n,"")||"",a=a.toString().replace(n,"")||"",i=(r||(t=t.replace(c,""),a=a.replace(c,"")),t.replace(e,"\0$1\0").replace(/\0$/,"").replace(/^\0/,"").split("\0")),p=a.replace(e,"\0$1\0").replace(/\0$/,"").replace(/^\0/,"").split("\0"),n=parseInt(t.match(l),10)||1!==i.length&&t.match(o)&&Date.parse(t),r=parseInt(a.match(l),10)||n&&a.match(o)&&Date.parse(a)||null;if(r){if(n]+)>)/gi,t=t.toString().replace(n,"")||"",a=a.toString().replace(n,"")||"",i=(r||(t=t.replace(c,""),a=a.replace(c,"")),t.replace(e,"\0$1\0").replace(/\0$/,"").replace(/^\0/,"").split("\0")),p=a.replace(e,"\0$1\0").replace(/\0$/,"").replace(/^\0/,"").split("\0"),n=parseInt(t.match(l),10)||1!==i.length&&t.match(o)&&Date.parse(t),r=parseInt(a.match(l),10)||n&&a.match(o)&&Date.parse(a)||null;if(r){if(n Date: Wed, 26 Jul 2023 21:40:41 +0100 Subject: [PATCH 2/3] Added bootstrap variant of input pagination plugin --- pagination/bootstrap_input.js | 42 +++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 pagination/bootstrap_input.js diff --git a/pagination/bootstrap_input.js b/pagination/bootstrap_input.js new file mode 100644 index 0000000..c05c3d6 --- /dev/null +++ b/pagination/bootstrap_input.js @@ -0,0 +1,42 @@ +/** + * Plug-in offers the same functionality as `default` pagination type + * (see `pagingType` option) but with input field for jumping pages, for use with bootstrap theme. + * + * @example + * $(document).ready(function() { + * $('#example').dataTable( { + * "pagingType": "bootstrap_input" + * } ); + * } ); + */ + +$.fn.DataTable.ext.pager.bootstrap_input = function(page, pages){ + return [ 'first', 'previous', 'input', 'next', 'last' ]; +}; + + +main_pageButtonFunc = $.fn.DataTable.ext.renderer.pageButton.bootstrap + +$.fn.DataTable.ext.renderer.pageButton = $.extend( true, $.fn.DataTable.ext.renderer.pageButton, + { + bootstrap: function ( settings, host, idx, buttons, page, pages ) { + main_pageButtonFunc(settings, host, idx, buttons, page, pages); + + input_html = '
' + + '' + + ' of ' + pages + '' + + '
' + + input_section = $(host).find("[data-dt-idx='input']"); + input_section.closest("li").prop("onclick", null).off("click"); + input_section.closest("li").prop("onkeypress", null).off("keypress"); + input_section.replaceWith(input_html); + + const api = new DataTable.Api(settings); + + $(host).find("ul.pagination input").val(page + 1).on('change', function(e){ + api.page(Number($(e.target).val()) - 1).draw('page'); + }); + } + } + ) From aa274500d97525901d173b0b6d86a7be20e8677d Mon Sep 17 00:00:00 2001 From: Stephen Tomkinson Date: Wed, 26 Jul 2023 21:46:36 +0100 Subject: [PATCH 3/3] Fix inconsistent whitespace --- pagination/bootstrap_input.js | 38 +++++++++++++++++------------------ 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/pagination/bootstrap_input.js b/pagination/bootstrap_input.js index c05c3d6..abbe683 100644 --- a/pagination/bootstrap_input.js +++ b/pagination/bootstrap_input.js @@ -10,33 +10,33 @@ * } ); */ -$.fn.DataTable.ext.pager.bootstrap_input = function(page, pages){ - return [ 'first', 'previous', 'input', 'next', 'last' ]; +$.fn.DataTable.ext.pager.bootstrap_input = function (page, pages) { + return ['first', 'previous', 'input', 'next', 'last']; }; main_pageButtonFunc = $.fn.DataTable.ext.renderer.pageButton.bootstrap -$.fn.DataTable.ext.renderer.pageButton = $.extend( true, $.fn.DataTable.ext.renderer.pageButton, +$.fn.DataTable.ext.renderer.pageButton = $.extend(true, $.fn.DataTable.ext.renderer.pageButton, { - bootstrap: function ( settings, host, idx, buttons, page, pages ) { - main_pageButtonFunc(settings, host, idx, buttons, page, pages); + bootstrap: function (settings, host, idx, buttons, page, pages) { + main_pageButtonFunc(settings, host, idx, buttons, page, pages); - input_html = '
' + - '' + - ' of ' + pages + '' + - '
' + input_html = '
' + + '' + + ' of ' + pages + '' + + '
' - input_section = $(host).find("[data-dt-idx='input']"); - input_section.closest("li").prop("onclick", null).off("click"); - input_section.closest("li").prop("onkeypress", null).off("keypress"); - input_section.replaceWith(input_html); + let input_section = $(host).find("[data-dt-idx='input']"); + input_section.closest("li").prop("onclick", null).off("click"); + input_section.closest("li").prop("onkeypress", null).off("keypress"); + input_section.replaceWith(input_html); - const api = new DataTable.Api(settings); + const api = new DataTable.Api(settings); - $(host).find("ul.pagination input").val(page + 1).on('change', function(e){ - api.page(Number($(e.target).val()) - 1).draw('page'); - }); - } + $(host).find("ul.pagination input").val(page + 1).on('change', function (e) { + api.page(Number($(e.target).val()) - 1).draw('page'); + }); + } } - ) +)