From 7a33105b783929da8c7adc16864494c1cd231b7d Mon Sep 17 00:00:00 2001 From: Jake Bentvelzen Date: Thu, 30 Jul 2015 15:25:30 +1000 Subject: [PATCH] Fix bug where the current sort value is pulled from the base table if the sortField has the same name when using ManyManyList --- code/GridFieldOrderableRows.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/code/GridFieldOrderableRows.php b/code/GridFieldOrderableRows.php index 0c3698d..bb8a1ec 100755 --- a/code/GridFieldOrderableRows.php +++ b/code/GridFieldOrderableRows.php @@ -238,7 +238,25 @@ class GridFieldOrderableRows extends RequestHandler implements $this->populateSortValues($items); // Generate the current sort values. - $current = $items->map('ID', $field)->toArray(); + if ($items instanceof ManyManyList) + { + $current = array(); + foreach ($items->toArray() as $record) + { + // NOTE: _SortColumn0 is the first ->sort() field + // used by SS when functions are detected in a SELECT + // or CASE WHEN. + if (isset($record->_SortColumn0)) { + $current[$record->ID] = $record->_SortColumn0; + } else { + $current[$record->ID] = $record->$field; + } + } + } + else + { + $current = $items->map('ID', $field)->toArray(); + } // Perform the actual re-ordering. $this->reorderItems($list, $current, $ids);