mirror of
https://github.com/symbiote/silverstripe-gridfieldextensions.git
synced 2024-10-22 15:05:39 +00:00
FIX: Fixed move to prev/next page functionality (fixes #307)
This commit is contained in:
parent
1bd74e0070
commit
80a4d9c311
@ -521,28 +521,44 @@ class GridFieldOrderableRows extends RequestHandler implements
|
|||||||
|
|
||||||
if ($to == 'prev') {
|
if ($to == 'prev') {
|
||||||
$swap = $list->limit(1, ($page - 1) * $per - 1)->first();
|
$swap = $list->limit(1, ($page - 1) * $per - 1)->first();
|
||||||
$values[$swap->ID] = $swap->$field;
|
$order[$swap->$field] = $id;
|
||||||
|
|
||||||
$order[] = $id;
|
reset($existing);
|
||||||
$order[] = $swap->ID;
|
$isMovingFirstItemOnPage = (key($existing) == $id);
|
||||||
|
$swappedItemNewSort = current($existing);
|
||||||
|
$order[$swappedItemNewSort] = $swap->ID;
|
||||||
|
|
||||||
foreach ($existing as $_id => $sort) {
|
// We want the item that's being swapped from the previous page to appear at the start
|
||||||
if ($id != $_id) {
|
// of the current page, so we have to adjust the sort order of all the items between the
|
||||||
$order[] = $_id;
|
// start of the page and the location of the item we're moving
|
||||||
|
if (!$isMovingFirstItemOnPage) {
|
||||||
|
foreach ($existing as $_id => $sort) {
|
||||||
|
if ($id == $_id) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
$order[$sort + 1] = $_id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} elseif ($to == 'next') {
|
} elseif ($to == 'next') {
|
||||||
$swap = $list->limit(1, $page * $per)->first();
|
$swap = $list->limit(1, $page * $per)->first();
|
||||||
$values[$swap->ID] = $swap->$field;
|
$order[$swap->$field] = $id;
|
||||||
|
|
||||||
foreach ($existing as $_id => $sort) {
|
end($existing);
|
||||||
if ($id != $_id) {
|
$isMovingLastItemOnPage = (key($existing) == $id);
|
||||||
$order[] = $_id;
|
$swappedItemNewSort = current($existing);
|
||||||
|
$order[$swappedItemNewSort] = $swap->ID;
|
||||||
|
|
||||||
|
// We want the item that's being swapped from the next page to appear at the end
|
||||||
|
// of the current page, so we have to adjust the sort order of all the items between the
|
||||||
|
// end of the page and the location of the item we're moving
|
||||||
|
if (!$isMovingLastItemOnPage) {
|
||||||
|
foreach (array_reverse($existing, true) as $_id => $sort) {
|
||||||
|
if ($id == $_id) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
$order[$sort - 1] = $_id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$order[] = $swap->ID;
|
|
||||||
$order[] = $id;
|
|
||||||
} else {
|
} else {
|
||||||
$this->httpError(400, 'Invalid page target');
|
$this->httpError(400, 'Invalid page target');
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user