code/VersionedGridFieldOrderableRows.php
public function handleMoveToPage(GridField $grid, $request)
    {
        if (!$paginator = $grid->getConfig()->getComponentByType('GridFieldPaginator')) {
            $this->httpError(404, 'Paginator component not found');
        }

        $move = $request->postVar('move');
        $field = $this->getSortField();

        $list = $grid->getList();
        $manip = $grid->getManipulatedList();

        $existing = $manip->map('ID', $field)->toArray();
        $values = $existing;
        $order = array();

        $id = isset($move['id']) ? (int)$move['id'] : null;
        $to = isset($move['page']) ? $move['page'] : null;

        if (!isset($values[$id])) {
            $this->httpError(400, 'Invalid item ID');
        }

        $this->populateSortValues($list);

        $page = ((int)$grid->getState()->GridFieldPaginator->currentPage) ?: 1;
        $per = $paginator->getItemsPerPage();

        if ($to == 'prev') {
            $swap = $list->limit(1, ($page - 1) * $per - 1)->first();
            $values[$swap->ID] = $swap->$field;

            $order[] = $id;
            $order[] = $swap->ID;

            foreach ($existing as $_id => $sort) {
                if ($id != $_id) $order[] = $_id;
            }
        } elseif ($to == 'next') {
            $swap = $list->limit(1, $page * $per)->first();
            $values[$swap->ID] = $swap->$field;

            foreach ($existing as $_id => $sort) {
                if ($id != $_id) $order[] = $_id;
            }

            $order[] = $swap->ID;
            $order[] = $id;
        } else {
            $this->httpError(400, 'Invalid page target');
        }

        $this->reorderItems($list, $values, $order);

        return $grid->FieldHolder();
    }
public function handleMoveToPage(GridField $grid, $request)
    {
        if (!$paginator = $grid->getConfig()->getComponentByType('GridFieldPaginator')) {
            $this->httpError(404, 'Paginator component not found');
        }

        $move = $request->postVar('move');
        $field = $this->getSortField();

        $list = $grid->getList();
        $manip = $grid->getManipulatedList();

        $existing = $manip->map('ID', $field)->toArray();
        $values = $existing;
        $order = array();

        $id = isset($move['id']) ? (int)$move['id'] : null;
        $to = isset($move['page']) ? $move['page'] : null;

        if (!isset($values[$id])) {
            $this->httpError(400, 'Invalid item ID');
        }

        $this->populateSortValues($list);

        $page = ((int)$grid->getState()->GridFieldPaginator->currentPage) ?: 1;
        $per = $paginator->getItemsPerPage();

        if ($to == 'prev') {
            $swap = $list->limit(1, ($page - 1) * $per - 1)->first();
            $values[$swap->ID] = $swap->$field;

            $order[] = $id;
            $order[] = $swap->ID;

            foreach ($existing as $_id => $sort) {
                if ($id != $_id) $order[] = $_id;
            }
        } elseif ($to == 'next') {
            $swap = $list->limit(1, $page * $per)->first();
            $values[$swap->ID] = $swap->$field;

            foreach ($existing as $_id => $sort) {
                if ($id != $_id) $order[] = $_id;
            }

            $order[] = $swap->ID;
            $order[] = $id;
        } else {
            $this->httpError(400, 'Invalid page target');
        }

        $this->reorderItems($list, $values, $order);

        return $grid->FieldHolder();
    }
public function handleMoveToPage ( GridField $ grid , $ request ) { if ( ! $ paginator = $ grid -> getConfig ( ) -> getComponentByType ( 'GridFieldPaginator' ) ) { $ this -> httpError ( 404 , 'Paginator component not found' ) ; } $ move = $ request -> postVar ( 'move' ) ; $ field = $ this -> getSortField ( ) ; $ list = $ grid -> getList ( ) ; $ manip = $ grid -> getManipulatedList ( ) ; $ existing = $ manip -> map ( 'ID' , $ field ) -> toArray ( ) ; $ values = $ existing ; $ order = array ( ) ; $ id = isset ( $ move [ 'id' ] ) ? ( int ) $ move [ 'id' ] : null ; $ to = isset ( $ move [ 'page' ] ) ? $ move [ 'page' ] : null ; if ( ! isset ( $ values [ $ id ] ) ) { $ this -> httpError ( 400 , 'Invalid item ID' ) ; } $ this -> populateSortValues ( $ list ) ; $ page = ( ( int ) $ grid -> getState ( ) -> GridFieldPaginator -> currentPage ) ? : 1 ; $ per = $ paginator -> getItemsPerPage ( ) ; if ( $ to == 'prev' ) { $ swap = $ list -> limit ( 1 , ( $ page - 1 ) * $ per - 1 ) -> first ( ) ; $ values [ $ swap -> ID ] = $ swap -> $ field ; $ order [ ] = $ id ; $ order [ ] = $ swap -> ID ; foreach ( $ existing as $ _id => $ sort ) { if ( $ id != $ _id ) $ order [ ] = $ _id ; } } elseif ( $ to == 'next' ) { $ swap = $ list -> limit ( 1 , $ page * $ per ) -> first ( ) ; $ values [ $ swap -> ID ] = $ swap -> $ field ; foreach ( $ existing as $ _id => $ sort ) { if ( $ id != $ _id ) $ order [ ] = $ _id ; } $ order [ ] = $ swap -> ID ; $ order [ ] = $ id ; } else { $ this -> httpError ( 400 , 'Invalid page target' ) ; } $ this -> reorderItems ( $ list , $ values , $ order ) ; return $ grid -> FieldHolder ( ) ; }
Handles requests to move an item to the previous or next page.

@param GridField $grid
@param $request
@return mixed
Handles requests to move an item to the previous or next page .