silverstripe / silverstripe-framework

Silverstripe Framework, the MVC framework that powers Silverstripe CMS
https://www.silverstripe.org
BSD 3-Clause "New" or "Revised" License
722 stars 822 forks source link

Enable gridfield previous / next record buttons where no paginator exists #9296

Open tractorcow opened 5 years ago

tractorcow commented 5 years ago

Affected Version

4.4, possibly 4.3

Description

According to https://github.com/silverstripe/silverstripe-framework/issues/8951, the previous / next buttons were intentionally disabled on gridfields without paginator. However, the calculations for getAdjacentRecordID are unnecessarily dependant on paginator in the first place. For small lists (such as fields in a form) that do not require pagination, it should be simple to treat the data list as a single page with page size = record list count.

Instead getAdjacentRecord refuses to calculate adjacent ID unless there's a paginator, resulting in no pagination controls at all.

Steps to Reproduce

Add a modeladmin without paginator for any class.

    public function getEditForm($id = null, $fields = null)
    {
        $form = parent::getEditForm($id, $fields);

            $gridField = $form->Fields()->dataFieldByName($this->sanitiseClassName($this->modelClass));
            if ($gridField instanceof GridField) {
                $gridField
                    ->getConfig()
                    ->removeComponentsByType([
                        GridFieldPaginator::class,
                        GridFieldPageCount::class,
                    ]);
            }

        return $form;
    }

Edit a record, and there will be no prev / next button.

lekoala commented 3 years ago

@tractorcow Just noticed a similar kind of issue. I was using a nested gridfield, and somehow it seems the state for that gridfield is not saved properly. therefore, everything works fine on the first page for prev/next, but after the first page, it breaks quite badly. I've stumbled upon this when implementing save and next and prev and next in my https://github.com/lekoala/silverstripe-cms-actions/commit/9447cfa9e505251447035b2e212f94c69dcba601. I ended up giving up tracking why the state is not set properly and implementing my own prev/next method on the dataobject.

at least my buttons are working, even if the prev/next arrow are still broken :-)