When attempting to re-order a view with the "show row weights" toggle enabled the new order is not saved.
You can replicate this problem by:
- Creating a view that allows drag & drop re-ordering with draggable views
- Visit the view
- Click the "show row weights" option
- Change the values of items in the list by changing the select lists shown
- Save
- Refresh the page and note that your new order is NOT saved.
However, if you re-order using the drag and drop method it works fine.
This is because the draggableviews_handler_native
has some logic which recounts the weights starting from 0 and incrementing +1 while looping over the returned results in $form_state. When using drag & drop the order of the results that are returned in the $form_state array is manipulated before saving so that they are in the correct order. However, when you use the select list method they are not. The values are still sent to the server in the same order as displayed on the page and thus the weights are never updated. In order to fix this we need to use the $item['weight'] value sent from the select list in the form and not try and re-index the weights starting at 0.
Comment | File | Size | Author |
---|---|---|---|
#12 | draggableviews-reorder_by_weight-2174287-2.patch | 1.29 KB | chasingmaxwell |
Comments
Comment #1
spidersilk CreditAttribution: spidersilk commentedI'm experiencing this issue too.
I was originally having problems in 7.x-2.0 with row ordering not working at all, via either method - it did save the row weights to the database, but that wasn't reflected on the page - the order of the rows stayed the same no matter what, and if you showed the row weights, they were all set to the negative of the number of rows (i.e. -2 if there were 2 rows).
So I upgraded to the dev version and now changing the order via drag-and-drop now works properly (the row weights are saved to the database, and the order on the page changes). But setting the row weights via the row weight drop-downs doesn't work - and now the weights aren't even being saved to the database.
This is not as big a problem as the original, because at least now the order CAN be set using drag and drop, but it would still be nice if both methods worked.
Comment #2
DarrellDuane CreditAttribution: DarrellDuane commentedI was having the same problem. I was able to fix this problem by clicking on [Settings] within the Format section
and disable the sorting that was configured in this area.
Comment #3
freeform.steph CreditAttribution: freeform.steph commentedCan confirm that using the dev version (7.x-2.0+56-dev) works with draggable, but not with manually selection using the 'show row weights' method
On our site this stopped working after some time of working fine, the solution we found was to ensure caching was disabled for this view.
Comment #4
DSquaredB CreditAttribution: DSquaredB commentedConfirming that updating to 7.x-2.0+56-dev works with draggable.
Comment #5
zhuber CreditAttribution: zhuber commentedI'm also able to replicate this issue. I've also realized that the sorting functionality for the draggable handles only works with Table formatted views, while the weight options show up for all views formats (although they still don't work).
Comment #6
zhuber CreditAttribution: zhuber commentedComment #7
betoscopioConfirming the solution with 7.x-2.0+56-dev version using draggable handles and not working with weight options.
Comment #8
purvimehta CreditAttribution: purvimehta commentedHello Guys,
Is there any solution available for drag and drop down method not saving weight?I am in very critical condition of project.My client needs that method working.If anyone have idea,please share!!
Thanks,
Purvi Mehta
Comment #9
iStryker CreditAttribution: iStryker commentedI can confirm this is an issue in the latest +60ish dev
Comment #10
kristin.e CreditAttribution: kristin.e commentedI can also confirm draggable option not working for +64 dev.
Comment #11
cpa2client CreditAttribution: cpa2client commentedI can confirm this problem, handles or weights do not change sort order.!!!. Any ideas of how to fix this.
Comment #12
chasingmaxwell CreditAttribution: chasingmaxwell commentedI'm attaching a patch which should fix this. I'm simply reordering the array by weight before iterating over the items.
Comment #13
chasingmaxwell CreditAttribution: chasingmaxwell commentedComment #14
t2000k CreditAttribution: t2000k commented#12 works for me!
Thanks a lot!
But if i set the numbers to 1, 2, 3 after i click save the numbers are -3, -2, -1.
That don't looks good ... even if it works :-)
Comment #15
iStryker CreditAttribution: iStryker commentedThats how drupal works if you have 3 things, then the range is -3 to 3. so the first numbers are -3, -2, -1.
Comment #16
ron_s CreditAttribution: ron_s commentedI can confirm that #12 fixes the issue for me. Thanks for the patch.
Comment #17
iStryker CreditAttribution: iStryker commentedI am amazed this patch works. Something tells me something else is broken, but if you re sort them, then everything is good. I will try to have a look at this when I get a chance.
Comment #19
iStryker CreditAttribution: iStryker commentedTested patch myself and it fixes the problem.
Comment #20
kristin.e CreditAttribution: kristin.e commentedHi, I've applied the patch but I still can't save ordering using either row heights or draggable handlers. It keeps reverting to the same order as before. Any other suggestions? Thanks in advance.
Comment #21
kristin.e CreditAttribution: kristin.e commentedComment #22
iStryker CreditAttribution: iStryker commentedKristin.e Saving with the draggable handler work. I suspect you are having a different problem. Do you have expose filters or either view? If so then this not your issue and you should read documentation on saving/using arguments.
Comment #23
ron_s CreditAttribution: ron_s commentedkristin.e, I'd also remind that this patch is applied to 7.x-2.x-dev, not 7.x-2.1. Download and install -dev and see if you're getting the results you expect. Otherwise follow the suggestions provided by @iStryker.
Comment #24
kristin.e CreditAttribution: kristin.e commentedThanks for the suggestions. I tried the patch on the dev version but still no luck.
I probably missed something when trying to explain what I'm trying to achieve. I have groups of pages organised under Taxonomy term names and I'm trying to order the pages within each Term name as well as the Taxonomy terms themselves.
I have a view set up with the fields:
(term) Taxonomy term: Name
Content: Title.
For the sort view I've used the following fields:
Content: Nid (Nid)
(term) Taxonomy term: Name
Content: Title
(term) Draggableviews: Taxonomy term (Taxonomy term)
Now I'm able to sort the views by Taxonomy term: Name but the Content:Titles don't save once I've dragged them to the positions I want. I've also tried using the row weights but ALL they keep defaulting back to -14. I know I'm missing something here so would be great to get any suggestions on this. Thanks again.
Comment #25
iStryker CreditAttribution: iStryker commentedHi Kristin.e, please do not keep commenting in this issue. Can you open a new support request ticket and I'll help you there. I rather you not congest/clutter up this issue, making it harder for others to actually read it. When you open a new support request please include/export your view in a text file and attach it to the issue. The simplier the view, the more easier to troubleshoot.
Comment #26
kristin.e CreditAttribution: kristin.e commentedSure will do - makes sense. don't want to clutter.
Comment #28
David_Rothstein CreditAttribution: David_Rothstein commentedThis commit seems to have broken some things - see the linked issue for a fix.