New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add "Reset Orders" to Sortable pages #1923
Comments
Have you tried setting the position in the database manually or recreating the records all together? If you implemented the sort_order column after creating the records all the entries have the same position and maybe won't be sorted correctly. |
@tobias-kuendig interesting, gonna try that, I was indeed thinking it could be coming from that. I was also exploring the JS to see if it was coming from there and created a very nifty dirty hack to make the system working in \modules\backend\behaviors\reordercontroller\assets\jsoctober.reorder.js
|
@tobias-kuendig ok you are right, once the sort order column filled in the DB, the system is working as expected. So to sum up
I guess it is not ideal, I have right now 4 entries but what if someone need to implement the reorder system on a model with hundred of entries? The best would be to have an initialization that provide a first ordering if it detects the whole column "sort_order" is Null. I can do a pull request on that point |
I think we need a "Reset Order Positions" button or something like this. It can be an issue for the NestedTree behavior too when this becomes corrupted. Refs: rainlab/blog-plugin#195 |
I'm not seeing this being set correctly on new items either. (Always defaults to "0") I ended up adding something like this to get it working for now:
|
It seems to me at least if the Trait is set in the model upon creation values are filled in automatically. |
When I create new records, the EDIT: I can confirm that the sorting function only works when the field name is |
Adding the Sortable trait to a model that has existing records will require a migration script to set the order values (a good idea is to copy them from the record IDs). Providing a "Reset Orders" button would also work as a solution. |
Documents how to prepare existing data to be used with the Sortable trait. Related: octobercms/october#1923
The support demand for October is increasing, while the available time the founders have to give remains the same. These issues will be handled in time, however there are ways you can help:
|
This bug still persists, correct? I'm using sorting on a relation and have managed to get it working great but the sorting doesn't happen since the post('sort_orders') value is always zeroes and literally the database call updates the sorting column to all zeroes.
|
Yes, you need to follow the instructions in octobercms/docs@e07d603 if you are adding the trait to a table that already has data. |
Ah, so this bug occurs because the initial sort order doesn't exist! Thanks for the comment man... I thought this was due to something else and wrote a crude workaround to make it work in my case...:
And in my model I had added:
Setting the sort_order to copy it's own record ID as suggested by to docs wouldn't work in my case since I'm using this against a relation. So now each set of related model elements have a sort order spanning from 0..n related to the parent model they belong to. In other words, the sort_order column is unique numbers only for a given parent_id rather than the entire related model itself. |
@SaifurRahmanMohsin Regarding using sort order on related records, the ID method still works since the relation will load only the relevant records and they will be in the appropriate order even if their sort orders are 5,7,13 instead of 1,2,3 |
This issue will be closed and archived in 3 days, as there has been no activity in the last 30 days. If this issue is still relevant or you would like to see action on it, please respond and we will get the ball rolling. |
Hello, Thanks first for that awesome CMS, lifechanger!
I stumbled upon a problem on the Reorder/sorting list system in the backend. I followed the documentation https://octobercms.com/docs/backend/reorder and successfully created the backend pages and all the pieces looks working fine. (Btw, it would be interesting to add the fact the dev needs to add a column on the database on the selected model called "sort_order", surely integer and nullable to make it working)
config_reorder.yaml
Controller file
Model file
reorder.htm
There is only one big problem : The order is not taken in account. I digged abit inside the code and saw that the order set is always 0. Here is an extract of the db queries operations on the admin page admin/ten31/programmes/budgets/reorder
When I output the values of the Trait \October\Rain\Database\Traits\Sortable with debugbar like :
I get the following result, looks like a bug, no?
The text was updated successfully, but these errors were encountered: