From 33f3dde41d7254c65091d32172dc140dfab8a664 Mon Sep 17 00:00:00 2001 From: David Toews Date: Tue, 24 Aug 2021 11:12:44 -0600 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=90=9B=20(cms=20interface)=20applies?= =?UTF-8?q?=20default=20sort=20order=20to=20CMS=20ordering?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This allows secondary sort ordering to be applied when it exists and when the objects have not been sorted manually --- src/GridFieldOrderableRows.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/GridFieldOrderableRows.php b/src/GridFieldOrderableRows.php index b94e085..2763065 100755 --- a/src/GridFieldOrderableRows.php +++ b/src/GridFieldOrderableRows.php @@ -8,6 +8,7 @@ use SilverStripe\Control\HTTPResponse_Exception; use SilverStripe\Control\RequestHandler; use SilverStripe\Core\ClassInfo; +use SilverStripe\Core\Config\Config; use SilverStripe\Forms\GridField\GridField; use SilverStripe\Forms\GridField\GridField_ColumnProvider; use SilverStripe\Forms\GridField\GridField_DataManipulator; @@ -359,7 +360,15 @@ public function getManipulatedData(GridField $grid, SS_List $list) // Fix bug in 3.1.3+ where ArrayList doesn't account for quotes $sortterm .= $this->getSortTable($list).'.'.$this->getSortField(); } else { + // If not an ArrayList it's definitely a DataList right? + // Or do we need another conditional here? $sortterm .= '"'.$this->getSortTable($list).'"."'.$this->getSortField().'"'; + $classname = $list->dataClass(); // DataLists have a dataClass + if (Config::inst()->get($list->dataClass(), 'default_sort')) { + // Append the default sort to the end of the sort string + // This may result in redundancy... but it seems to work + $sortterm .= ', ' . Config::inst()->get($classname, 'default_sort'); + } } return $list->sort($sortterm); } From 65cbe10c9780e11df4635173d86a23c4838ce6c3 Mon Sep 17 00:00:00 2001 From: David Toews Date: Thu, 25 Nov 2021 14:51:51 -0700 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=90=9B=20(sort=20logic)=20adds=20addi?= =?UTF-8?q?tional=20checks=20for=20non=20DataList=20or=20unsorted=20cases?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/GridFieldOrderableRows.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/GridFieldOrderableRows.php b/src/GridFieldOrderableRows.php index 2763065..4acbcc4 100755 --- a/src/GridFieldOrderableRows.php +++ b/src/GridFieldOrderableRows.php @@ -360,16 +360,19 @@ public function getManipulatedData(GridField $grid, SS_List $list) // Fix bug in 3.1.3+ where ArrayList doesn't account for quotes $sortterm .= $this->getSortTable($list).'.'.$this->getSortField(); } else { - // If not an ArrayList it's definitely a DataList right? - // Or do we need another conditional here? $sortterm .= '"'.$this->getSortTable($list).'"."'.$this->getSortField().'"'; - $classname = $list->dataClass(); // DataLists have a dataClass - if (Config::inst()->get($list->dataClass(), 'default_sort')) { - // Append the default sort to the end of the sort string - // This may result in redundancy... but it seems to work - $sortterm .= ', ' . Config::inst()->get($classname, 'default_sort'); + + if ($list instanceof DataList) { + $classname = $list->dataClass(); + if (Config::inst()->get($classname, 'default_sort')) { + // Append the default sort to the end of the sort string + // This may result in redundancy... but it seems to work + $sortterm .= $sortterm ? ', ' : ''; + $sortterm .= Config::inst()->get($classname, 'default_sort'); + } } } + return $list->sort($sortterm); } From 1436ead540a51b2a1e24c7c3ae9a01543aa465ed Mon Sep 17 00:00:00 2001 From: David Toews Date: Fri, 26 Nov 2021 09:09:48 -0700 Subject: [PATCH 3/3] Update src/GridFieldOrderableRows.php Co-authored-by: Michal Kleiner --- src/GridFieldOrderableRows.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/GridFieldOrderableRows.php b/src/GridFieldOrderableRows.php index 4acbcc4..70c2f66 100755 --- a/src/GridFieldOrderableRows.php +++ b/src/GridFieldOrderableRows.php @@ -364,11 +364,10 @@ public function getManipulatedData(GridField $grid, SS_List $list) if ($list instanceof DataList) { $classname = $list->dataClass(); - if (Config::inst()->get($classname, 'default_sort')) { + if ($defaultSort = Config::inst()->get($classname, 'default_sort')) { // Append the default sort to the end of the sort string // This may result in redundancy... but it seems to work - $sortterm .= $sortterm ? ', ' : ''; - $sortterm .= Config::inst()->get($classname, 'default_sort'); + $sortterm .= ($sortterm ? ', ' : '') . $defaultSort; } } }