From a07634f5d49aced710c07cbf83caf620614a9453 Mon Sep 17 00:00:00 2001 From: Vinnie Date: Wed, 17 Aug 2022 12:04:17 +1200 Subject: [PATCH 1/2] Create GridFieldOrderableRows.php --- src/GridFieldOrderableRows.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/GridFieldOrderableRows.php b/src/GridFieldOrderableRows.php index 6b3d8bb..e20df12 100755 --- a/src/GridFieldOrderableRows.php +++ b/src/GridFieldOrderableRows.php @@ -365,6 +365,11 @@ public function getManipulatedData(GridField $grid, SS_List $list) if ($list instanceof DataList) { $classname = $list->dataClass(); if ($defaultSort = Config::inst()->get($classname, 'default_sort')) { + // Check to see if `default_sort` is an array + if (is_array($defaultSort)) { + // If it is, use the first item, as that has highest priority + $defaultSort = array_shift($defaultSort); + } // Append the default sort to the end of the sort string // This may result in redundancy... but it seems to work $sortterm .= ($sortterm ? ', ' : '') . $defaultSort; From 6c0110432fbb4b3d6d0fb618c6d23c59ee526697 Mon Sep 17 00:00:00 2001 From: vinnie Date: Fri, 4 Nov 2022 15:19:04 +1300 Subject: [PATCH 2/2] stringify OrderableRows default sort array --- src/GridFieldOrderableRows.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/GridFieldOrderableRows.php b/src/GridFieldOrderableRows.php index e20df12..e5da805 100755 --- a/src/GridFieldOrderableRows.php +++ b/src/GridFieldOrderableRows.php @@ -365,11 +365,17 @@ public function getManipulatedData(GridField $grid, SS_List $list) if ($list instanceof DataList) { $classname = $list->dataClass(); if ($defaultSort = Config::inst()->get($classname, 'default_sort')) { + $defaultSortTerm = ''; + // Check to see if `default_sort` is an array if (is_array($defaultSort)) { - // If it is, use the first item, as that has highest priority - $defaultSort = array_shift($defaultSort); + foreach ($defaultSort as $col => $dir) { + $defaultSortTerm .= "$col $dir, "; + } + } else { + $defaultSortTerm = $defaultSort; } + // Append the default sort to the end of the sort string // This may result in redundancy... but it seems to work $sortterm .= ($sortterm ? ', ' : '') . $defaultSort;