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.
This commit is contained in:
Pieter Hollants 2015-01-18 19:48:37 +01:00
parent 79972af8a2
commit ffee8d4d35
1 changed files with 27 additions and 1 deletions

View File

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