diff --git a/src/GridFieldOrderableRows.php b/src/GridFieldOrderableRows.php index 37fd90d..c87e26f 100755 --- a/src/GridFieldOrderableRows.php +++ b/src/GridFieldOrderableRows.php @@ -396,6 +396,13 @@ public function getManipulatedData(GridField $grid, SS_List $list) if ($list instanceof DataList) { $classname = $list->dataClass(); if ($defaultSort = Config::inst()->get($classname, 'default_sort')) { + if (is_array($defaultSort)) { + $defaultSortArray = []; + foreach ($defaultSort as $column => $direction) { + $defaultSortArray[] = "\"$column\" $direction"; + } + $defaultSort = implode(', ', $defaultSortArray); + } // Append the default sort to the end of the sort string // This may result in redundancy... but it seems to work $sortterm .= ($sortterm ? ', ' : '') . $defaultSort; diff --git a/tests/GridFieldOrderableRowsTest.php b/tests/GridFieldOrderableRowsTest.php index 5d93d6b..6cf438b 100644 --- a/tests/GridFieldOrderableRowsTest.php +++ b/tests/GridFieldOrderableRowsTest.php @@ -25,6 +25,7 @@ use Symbiote\GridFieldExtensions\Tests\Stub\ThroughIntermediary; use Symbiote\GridFieldExtensions\Tests\Stub\TitleObject; use Symbiote\GridFieldExtensions\Tests\Stub\TitleSortedObject; +use Symbiote\GridFieldExtensions\Tests\Stub\TitleArraySortedObject; use Symbiote\GridFieldExtensions\Tests\Stub\ThroughIntermediaryVersioned; /** @@ -54,6 +55,7 @@ class GridFieldOrderableRowsTest extends SapphireTest ThroughBelongs::class, TitleObject::class, TitleSortedObject::class, + TitleArraySortedObject::class, ThroughDefinerVersioned::class, ThroughIntermediaryVersioned::class, ThroughBelongsVersioned::class, @@ -387,6 +389,16 @@ public function provideGetManipulatedData(): array ], ['B', 'A', 'C'] ], + [ + TitleArraySortedObject::class, + DataList::class, + [ + ['Title' => 'X', 'Iden' => 'C', 'OtherSort' => 3], + ['Title' => 'Z', 'Iden' => 'A', 'OtherSort' => 2], + ['Title' => 'Z', 'Iden' => 'B', 'OtherSort' => 1], + ], + ['C', 'B', 'A'] + ], ]; } } diff --git a/tests/Stub/TitleArraySortedObject.php b/tests/Stub/TitleArraySortedObject.php new file mode 100644 index 0000000..25d3f1a --- /dev/null +++ b/tests/Stub/TitleArraySortedObject.php @@ -0,0 +1,22 @@ + 'Varchar', + 'Iden' => 'Varchar', + 'OtherSort' => 'Int' + ]; + + private static array $default_sort = [ + 'Title' => 'ASC', + 'OtherSort' => 'ASC', + ]; + + private static $table_name = 'TitleArraySortedObject'; +}