mirror of
https://github.com/symbiote/silverstripe-gridfieldextensions.git
synced 2024-10-22 17:05:39 +02:00
commit
bb0a84d16a
@ -25,6 +25,22 @@ class GridFieldOrderableRows extends RequestHandler implements
|
|||||||
*/
|
*/
|
||||||
protected $sortField;
|
protected $sortField;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extra sort fields to apply before the sort field.
|
||||||
|
*
|
||||||
|
* @see setExtraSortFields()
|
||||||
|
* @var string|array
|
||||||
|
*/
|
||||||
|
protected $extraSortFields = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The number of the column containing the reorder handles
|
||||||
|
*
|
||||||
|
* @see setReorderColumnNumber()
|
||||||
|
* @var integer
|
||||||
|
*/
|
||||||
|
protected $reorderColumnNumber = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $sortField
|
* @param string $sortField
|
||||||
*/
|
*/
|
||||||
@ -50,6 +66,42 @@ class GridFieldOrderableRows extends RequestHandler implements
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string|array
|
||||||
|
*/
|
||||||
|
public function getExtraSortFields() {
|
||||||
|
return $this->extraSortFields;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets extra sort fields to apply before the sort field.
|
||||||
|
*
|
||||||
|
* @param string|array $fields
|
||||||
|
* @return GridFieldOrderableRows $this
|
||||||
|
*/
|
||||||
|
public function setExtraSortFields($fields) {
|
||||||
|
$this->extraSortFields = $fields;
|
||||||
|
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.
|
* Gets the table which contains the sort field.
|
||||||
*
|
*
|
||||||
@ -99,7 +151,7 @@ class GridFieldOrderableRows extends RequestHandler implements
|
|||||||
|
|
||||||
public function augmentColumns($grid, &$cols) {
|
public function augmentColumns($grid, &$cols) {
|
||||||
if(!in_array('Reorder', $cols) && $grid->getState()->GridFieldOrderableRows->enabled) {
|
if(!in_array('Reorder', $cols) && $grid->getState()->GridFieldOrderableRows->enabled) {
|
||||||
array_unshift($cols, 'Reorder');
|
array_splice($cols, $this->reorderColumnNumber, 0, 'Reorder');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,7 +180,18 @@ class GridFieldOrderableRows extends RequestHandler implements
|
|||||||
$state->GridFieldOrderableRows->enabled = !$sorted;
|
$state->GridFieldOrderableRows->enabled = !$sorted;
|
||||||
|
|
||||||
if(!$sorted) {
|
if(!$sorted) {
|
||||||
return $list->sort($this->getSortField());
|
$sortterm = '';
|
||||||
|
if ($this->extraSortFields) {
|
||||||
|
if (is_array($this->extraSortFields)) {
|
||||||
|
foreach($this->extraSortFields as $col => $dir) {
|
||||||
|
$sortterm .= "$col $dir, ";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$sortterm = $this->extraSortFields.', ';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$sortterm .= $this->getSortField();
|
||||||
|
return $list->sort($sortterm);
|
||||||
} else {
|
} else {
|
||||||
return $list;
|
return $list;
|
||||||
}
|
}
|
||||||
@ -150,7 +213,18 @@ class GridFieldOrderableRows extends RequestHandler implements
|
|||||||
$this->httpError(400);
|
$this->httpError(400);
|
||||||
}
|
}
|
||||||
|
|
||||||
$items = $list->byIDs($ids)->sort($field);
|
$sortterm = '';
|
||||||
|
if ($this->extraSortFields) {
|
||||||
|
if (is_array($this->extraSortFields)) {
|
||||||
|
foreach($this->extraSortFields as $col => $dir) {
|
||||||
|
$sortterm .= "$col $dir, ";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$sortterm = $this->extraSortFields.', ';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$sortterm .= $field;
|
||||||
|
$items = $list->byIDs($ids)->sort($sortterm);
|
||||||
|
|
||||||
// Ensure that each provided ID corresponded to an actual object.
|
// Ensure that each provided ID corresponded to an actual object.
|
||||||
if(count($items) != count($ids)) {
|
if(count($items) != count($ids)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user