From cc042d93127ae53bc24846ce5993dec641fbccf3 Mon Sep 17 00:00:00 2001 From: Pieter Hollants Date: Sun, 18 Jan 2015 19:48:37 +0100 Subject: [PATCH] GridFieldOrderableRows: Allow setting the reorder handles column's number Until now the column with the handles starting the reorder action always appeared as the first column at the left of the GridField. As a followup to the previous change's for extra sort fields, this change allows specifying a different column index. This way you can eg. move the handles behind a category column whose sorting will always be enforced, thus giving the user visual support in understanding the limits of drag-n-drop reordering. --- code/GridFieldOrderableRows.php | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/code/GridFieldOrderableRows.php b/code/GridFieldOrderableRows.php index 66d259c..7fdbae3 100755 --- a/code/GridFieldOrderableRows.php +++ b/code/GridFieldOrderableRows.php @@ -33,6 +33,14 @@ class GridFieldOrderableRows extends RequestHandler implements */ protected $extraSortFields = null; + /** + * The number of the column containing the reorder handles + * + * @see setReorderColumnNumber() + * @var integer + */ + protected $reorderColumnNumber = 0; + /** * @param string $sortField */ @@ -76,6 +84,24 @@ class GridFieldOrderableRows extends RequestHandler implements return $this; } + /** + * @return integer + */ + public function getReorderColumnNumber() { + return $this->reorderColumnNumber; + } + + /** + * Sets the number of the column containing the reorder handles. + * + * @param integer $colno + * @return GridFieldOrderableRows $this + */ + public function setReorderColumnNumber($colno) { + $this->reorderColumnNumber = $colno; + return $this; + } + /** * Gets the table which contains the sort field. * @@ -125,7 +151,7 @@ class GridFieldOrderableRows extends RequestHandler implements public function augmentColumns($grid, &$cols) { if(!in_array('Reorder', $cols) && $grid->getState()->GridFieldOrderableRows->enabled) { - array_unshift($cols, 'Reorder'); + array_splice($cols, $this->reorderColumnNumber, 0, 'Reorder'); } }