From b5fc64cf5d14db12b197071cff5be7ed3c4d79b3 Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Thu, 17 Dec 2020 17:33:24 +0100 Subject: [PATCH] Fixed DataTables numeric/datetime sorting (fixes #1085) --- changelog/60_UNRELEASED_2020-xx-xx.md | 1 + public/viewjs/batteriesoverview.js | 4 +++- public/viewjs/choresoverview.js | 5 ++++- public/viewjs/products.js | 3 ++- public/viewjs/recipes.js | 3 ++- public/viewjs/shoppinglist.js | 3 ++- public/viewjs/stockoverview.js | 6 +++++- public/viewjs/tasks.js | 3 ++- views/shoppinglist.blade.php | 28 +++++++++++++-------------- views/stockoverview.blade.php | 2 +- 10 files changed, 36 insertions(+), 22 deletions(-) diff --git a/changelog/60_UNRELEASED_2020-xx-xx.md b/changelog/60_UNRELEASED_2020-xx-xx.md index 93c19f3f..b0f48071 100644 --- a/changelog/60_UNRELEASED_2020-xx-xx.md +++ b/changelog/60_UNRELEASED_2020-xx-xx.md @@ -163,6 +163,7 @@ - More `config.php` settings (see the section `Component configuration for Quagga2`) to tweak Quagga2 (this is the component used for device camera for barcode scanning) (thanks @andrelam) - Some localization string fixes (thanks @duckfullstop) - Better error pages +- Fixed that numeric and date-time sorting of table columns did not work correctly - Fixed that XSS / HTML injection was possible through some user input fields (low severity / not really a problem as this could not be abused unauthenticated) - New translations: (thanks all the translators) - Greek (demo available at https://el.demo.grocy.info) diff --git a/public/viewjs/batteriesoverview.js b/public/viewjs/batteriesoverview.js index f89ac36e..43843947 100644 --- a/public/viewjs/batteriesoverview.js +++ b/public/viewjs/batteriesoverview.js @@ -2,7 +2,9 @@ 'order': [[2, 'desc']], 'columnDefs': [ { 'orderable': false, 'targets': 0 }, - { 'searchable': false, "targets": 0 } + { 'searchable': false, "targets": 0 }, + { "type": "html", "targets": 3 }, + { "type": "html", "targets": 4 } ].concat($.fn.dataTable.defaults.columnDefs) }); $('#batteries-overview-table tbody').removeClass("d-none"); diff --git a/public/viewjs/choresoverview.js b/public/viewjs/choresoverview.js index 98e87bc0..794c6d34 100644 --- a/public/viewjs/choresoverview.js +++ b/public/viewjs/choresoverview.js @@ -2,7 +2,10 @@ 'order': [[2, 'desc']], 'columnDefs': [ { 'orderable': false, 'targets': 0 }, - { 'searchable': false, "targets": 0 } + { 'searchable': false, "targets": 0 }, + { "type": "html", "targets": 5 }, + { "type": "html", "targets": 2 }, + { "type": "html", "targets": 3 } ].concat($.fn.dataTable.defaults.columnDefs) }); $('#chores-overview-table tbody').removeClass("d-none"); diff --git a/public/viewjs/products.js b/public/viewjs/products.js index d94b7ca4..b1de33ec 100644 --- a/public/viewjs/products.js +++ b/public/viewjs/products.js @@ -2,7 +2,8 @@ 'order': [[1, 'asc']], 'columnDefs': [ { 'orderable': false, 'targets': 0 }, - { 'searchable': false, "targets": 0 } + { 'searchable': false, "targets": 0 }, + { "type": "html-num-fmt", "targets": 3 } ].concat($.fn.dataTable.defaults.columnDefs) }); $('#products-table tbody').removeClass("d-none"); diff --git a/public/viewjs/recipes.js b/public/viewjs/recipes.js index ee48b654..dfa49020 100644 --- a/public/viewjs/recipes.js +++ b/public/viewjs/recipes.js @@ -2,7 +2,8 @@ 'order': [[1, 'asc']], 'columnDefs': [ { 'orderable': false, 'targets': 0 }, - { 'searchable': false, "targets": 0 } + { 'searchable': false, "targets": 0 }, + { "type": "html-num-fmt", "targets": 2 }, ].concat($.fn.dataTable.defaults.columnDefs), select: { style: 'single', diff --git a/public/viewjs/shoppinglist.js b/public/viewjs/shoppinglist.js index 084b7438..31875067 100644 --- a/public/viewjs/shoppinglist.js +++ b/public/viewjs/shoppinglist.js @@ -6,7 +6,8 @@ var shoppingListTable = $('#shoppinglist-table').DataTable({ 'columnDefs': [ { 'orderable': false, 'targets': 0 }, { 'searchable': false, "targets": 0 }, - { 'visible': false, 'targets': 3 } + { 'visible': false, 'targets': 3 }, + { "type": "num", "targets": 2 } ].concat($.fn.dataTable.defaults.columnDefs), 'rowGroup': { enable: true, diff --git a/public/viewjs/stockoverview.js b/public/viewjs/stockoverview.js index ba7f1e5b..8b42d340 100755 --- a/public/viewjs/stockoverview.js +++ b/public/viewjs/stockoverview.js @@ -10,7 +10,11 @@ { 'visible': false, 'targets': 2 }, { 'visible': false, 'targets': 4 }, { 'visible': false, 'targets': 9 }, - { 'visible': false, 'targets': 10 } + { 'visible': false, 'targets': 10 }, + { "type": "num", "targets": 3 }, + { "type": "html-num-fmt", "targets": 9 }, + { "type": "html-num-fmt", "targets": 10 }, + { "type": "html", "targets": 5 } ].concat($.fn.dataTable.defaults.columnDefs) }); diff --git a/public/viewjs/tasks.js b/public/viewjs/tasks.js index 0f28445b..722bb22f 100644 --- a/public/viewjs/tasks.js +++ b/public/viewjs/tasks.js @@ -3,7 +3,8 @@ 'columnDefs': [ { 'orderable': false, 'targets': 0 }, { 'searchable': false, "targets": 0 }, - { 'visible': false, 'targets': 3 } + { 'visible': false, 'targets': 3 }, + { "type": "html", "targets": 2 } ].concat($.fn.dataTable.defaults.columnDefs), 'rowGroup': { enable: true, diff --git a/views/shoppinglist.blade.php b/views/shoppinglist.blade.php index 7f40cff9..6e03c80f 100644 --- a/views/shoppinglist.blade.php +++ b/views/shoppinglist.blade.php @@ -231,20 +231,20 @@ data-product-id="{{ $listItem->product_id }}"> @if(!empty($listItem->product_id)) {{ FindObjectInArrayByPropertyValue($products, 'id', $listItem->product_id)->name }}
@endif{!! nl2br($listItem->note) !!} - - @if(!empty($listItem->product_id)) - @php - $listItem->amount_origin_qu = $listItem->amount; - $product = FindObjectInArrayByPropertyValue($products, 'id', $listItem->product_id); - $productQuConversions = FindAllObjectsInArrayByPropertyValue($quantityUnitConversionsResolved, 'product_id', $product->id); - $productQuConversions = FindAllObjectsInArrayByPropertyValue($productQuConversions, 'from_qu_id', $product->qu_id_stock); - $productQuConversion = FindObjectInArrayByPropertyValue($productQuConversions, 'to_qu_id', $listItem->qu_id); - if ($productQuConversion) - { - $listItem->amount = $listItem->amount * $productQuConversion->factor; - } - @endphp - @endif + @if(!empty($listItem->product_id)) + @php + $listItem->amount_origin_qu = $listItem->amount; + $product = FindObjectInArrayByPropertyValue($products, 'id', $listItem->product_id); + $productQuConversions = FindAllObjectsInArrayByPropertyValue($quantityUnitConversionsResolved, 'product_id', $product->id); + $productQuConversions = FindAllObjectsInArrayByPropertyValue($productQuConversions, 'from_qu_id', $product->qu_id_stock); + $productQuConversion = FindObjectInArrayByPropertyValue($productQuConversions, 'to_qu_id', $listItem->qu_id); + if ($productQuConversion) + { + $listItem->amount = $listItem->amount * $productQuConversion->factor; + } + @endphp + @endif + amount }}> {{ $listItem->amount }} @if(!empty($listItem->product_id)){{ $__n($listItem->amount, FindObjectInArrayByPropertyValue($quantityunits, 'id', $listItem->qu_id)->name, FindObjectInArrayByPropertyValue($quantityunits, 'id', $listItem->qu_id)->name_plural) }}@endif diff --git a/views/stockoverview.blade.php b/views/stockoverview.blade.php index 2e8e7d6c..2fd97809 100755 --- a/views/stockoverview.blade.php +++ b/views/stockoverview.blade.php @@ -305,7 +305,7 @@ @if($currentStockEntry->product_group_name !== null){{ $currentStockEntry->product_group_name }}@endif - + amount }}> {{ $currentStockEntry->amount }} {{ $__n($currentStockEntry->amount, $currentStockEntry->qu_unit_name, $currentStockEntry->qu_unit_name_plural) }}