From d9182a65d270615a694c416c003b25f29294119b Mon Sep 17 00:00:00 2001 From: Marcus Nyeholt Date: Thu, 3 Sep 2015 11:36:48 +1000 Subject: [PATCH] FIX incompatible list detection in framework Fixes issue raised in #98 - if using a non-DB List implementation, the field sort detection fails (ie in array list) so ordering doesn't work. --- code/GridFieldOrderableRows.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/code/GridFieldOrderableRows.php b/code/GridFieldOrderableRows.php index bb8a1ec..43f4a28 100755 --- a/code/GridFieldOrderableRows.php +++ b/code/GridFieldOrderableRows.php @@ -190,7 +190,7 @@ class GridFieldOrderableRows extends RequestHandler implements $sortterm = $this->extraSortFields.', '; } } - $sortterm .= '"'.$this->getSortTable($list).'"."'.$this->getSortField().'"'; + $sortterm .= $this->sortTerm($list); return $list->sort($sortterm); } else { return $list; @@ -226,7 +226,7 @@ class GridFieldOrderableRows extends RequestHandler implements $sortterm = $this->extraSortFields.', '; } } - $sortterm .= '"'.$this->getSortTable($list).'"."'.$field.'"'; + $sortterm .= $this->sortTerm($list); $items = $list->filter('ID', $ids)->sort($sortterm); // Ensure that each provided ID corresponded to an actual object. @@ -264,6 +264,21 @@ class GridFieldOrderableRows extends RequestHandler implements return $grid->FieldHolder(); } + /** + * Get a compatible sort term, taking into account DBs and their ANSI ness + * + * @see https://github.com/silverstripe-australia/silverstripe-gridfieldextensions/issues/98 + */ + protected function sortTerm($list) { + // need to handle ANSI escaping for DBs differently from other list types + if ($list instanceof DataList) { + $sortterm .= '"'.$this->getSortTable($list).'"."'.$this->getSortField().'"'; + } else { + $sortterm .= $this->getSortTable($list).'.'.$this->getSortField(); + } + } + + /** * Handles requests to move an item to the previous or next page. */