Fix bug where the current sort value is pulled from the base table if the sortField has the same name when using ManyManyList

This commit is contained in:
Jake Bentvelzen 2015-07-30 15:25:30 +10:00
parent bb6748e414
commit 7a33105b78

View File

@ -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);