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

chris15853
chris15853

Hi, I am trying to setup the reorder controller so that i can order how "Projects" are displayed in on the front end but I cannot seem to get it working.

I've tried to follow the documentation but it doesn't seem to be working.

In my Project Model I have replaced: use \October\Rain\Database\Traits\Validation; with use \October\Rain\Database\Traits\Sortable;

Then in my Projects Controller I have added 'Backend\Behaviors\ReorderController' to the $implement and also created the $reorderConfig.

Then in my Projects Controller subfolder I have created the config_reorder.yaml and the reorder.htm.

Can someone tell me what i'm missing? BTW i'm using the Builder plugin.

Thanks in advance Chris

Last updated

Crazymodder
Crazymodder

You need to make an

orderBy('sort_order', ASC|DESC); 

in your query for frontend listing.

chris15853
chris15853

Sorry what i meant is that i cannot get the reorder page to display in the backend so i cant reorder my projects.

philipptempel
philipptempel

You don't have to replace the Validation trait with the Sortable trait. They can coexist.

What exactly is missing? If you setup your controller like this it should work, however, you might not see it working. Either because you have a session value for a custom column sort-order, or because you do not have your list toolbar partial update to create a link to the reorder page. The reorder controller is a separate action to the controller. It won't show up anywhere in your list part, but is intended to be used separately. Thus you'll need a button to link to it. Check the rainlab/blog/controllers/categories/_list_toolbar.htm partial for the updated list toolbar content.

chris15853
chris15853

Thanks thats really helped, I've now been able to get the re-order button to display in the toolbar and link to the re-order view.

Im now having some issues with the order saving. If i re-order the projects and refresh the page it renders the old order. Do i need to add a "order" field to the database? Or am i missing something else.

To make things easier i've uploaded my code to Github: https://github.com/c-andrews/octobercms_projects_plugin

Thanks again for the help

Crazymodder
Crazymodder

Hi,

All your columns are sortable. Next problem I can't find any sort_order column in your migrations. At the end you have to order your list

Crazymodder said:

You need to make an

orderBy('sort_order', ASC|DESC);

in your query for frontend listing.

chris15853
chris15853

Hi, sorry i've tried to figure out where i put that but i am completely lost. I've changed the number of sortable columns so its just sort_order which is sortable.

Thanks for your help

Crazymodder
Crazymodder

Did you implement the sortable trait in your model and add the field sort_order to your migration?

chris15853
chris15853

Yes i'm using the following at the top of my Project Model: use \October\Rain\Database\Traits\Validation; use \October\Rain\Database\Traits\Sortable;

and i've got a field in the DB called sort_order

chris15853
chris15853

Is anyone able to help?

Crazymodder
Crazymodder

And in your db sort_order is getting filled with numbers like 1,2,3 etc?

chris15853
chris15853

Hi, no my sort_order was all 0's for some reason so i've now changed it to 1,2,3, etc and its now working. Thank you for your help. It was becoming quite frustrating.

Last updated

Crazymodder
Crazymodder

I think the reason is that you missed somethink to implement for reorder functionality. Maybe you check this plugin:

http://octobercms.com/plugin/benfreke-menumanager

There you can see how reorder was implemented.

sam12922
sam12922

Any update on this? I have exactly the same problem, and the menumanager plugin uses NestedTree, which is different...

aleshka
aleshka

Same problem, first plugin working good, second only 0's in DB...

Jan van de Laar
Jan van de Laar

I got the same problem. And just as chris15853 did, I changed the zero's in the databasefields to numbers,(1,2,3 etc) and after that all was working. Really weird. Maybe some databasedude knows the anwser...

Last updated

Minius
Minius

db field sort_order must be type of integer, not string. And then all good:)

gavinfostered11132
gavinfostered11132

This is a reported bug. If you implement the sortable trait AFTER the records have been entered you must manually set the ordering in the database for existing records. All new records will be fine. Here's some more information on the bug

https://github.com/octobercms/october/issues/1923#issuecomment-208208793

1-18 of 18

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