From 29fb2d3885809aa25be5f70fb51e466b6b00df39 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Tue, 15 Jun 2021 10:33:42 -0400 Subject: [PATCH] Add special handling of sorting by EndTime because it can be NULL. Fixes #3298 --- web/ajax/events.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/web/ajax/events.php b/web/ajax/events.php index 8a8e3a4f1..562cce9c2 100644 --- a/web/ajax/events.php +++ b/web/ajax/events.php @@ -38,10 +38,20 @@ $search = isset($_REQUEST['search']) ? $_REQUEST['search'] : ''; // Bootstrap table sends json_ecoded array, which we must decode $advsearch = isset($_REQUEST['advsearch']) ? json_decode($_REQUEST['advsearch'], JSON_OBJECT_AS_ARRAY) : array(); +// Order specifies the sort direction, either asc or desc +$order = (isset($_REQUEST['order']) and (strtolower($_REQUEST['order']) == 'asc')) ? 'ASC' : 'DESC'; + // Sort specifies the name of the column to sort on $sort = 'StartDateTime'; -if ( isset($_REQUEST['sort']) ) { +if (isset($_REQUEST['sort'])) { $sort = $_REQUEST['sort']; + if ($sort == 'EndDateTime') { + if ($order == 'ASC') { + $sort = 'EndDateTime IS NULL, EndDateTime'; + } else { + $sort = 'EndDateTime IS NOT NULL, EndDateTime'; + } + } } // Offset specifies the starting row to return, used for pagination @@ -54,8 +64,6 @@ if ( isset($_REQUEST['offset']) ) { } } -// Order specifies the sort direction, either asc or desc -$order = (isset($_REQUEST['order']) and (strtolower($_REQUEST['order']) == 'asc')) ? 'ASC' : 'DESC'; // Limit specifies the number of rows to return // Set the default to 0 for events view, to prevent an issue with ALL pagination