This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

kerby
kerby

I want to reorder list of related models in form view using drag'n'drop. Is it possible?

I know about https://octobercms.com/docs/backend/reorder but I can't find a way to make it work with related models list.

thepottingshed
thepottingshed

I too have been wondering about this.

FabriZZio
FabriZZio

Tried making some kind of combination of both functionalities by myself, but I'm lost here too...

triasrahman
slouma.touati14302
arrcrown
jakobf
jakobf

Model Scenario: Project belongsto Category

In the corresponding controller use:

    public function reorderExtendQuery($query)
    {
        if (isset($this->params[0])) {
            $query->where('category_id', (int) $this->params[0]);
        }
        else {
            throw new \Exception('Category\'s ID must be given for reordering of Projects.');
        }
    }

to limit the Project $query for the reorder action.

You can leave the else-statement out, if you want to allow the Controller to also be able to order the whole list, instead of the related context (here the parent's category id). Also make sure that you link to the reorder route with the (optional) first parameter of the parent (here category_id), to limit the reorder list of Projects.

I hope this helps.

Last updated

1-7 of 7

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.