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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

spidersilk’s picture

I'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.

DarrellDuane’s picture

I 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.

freeform.steph’s picture

Can 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.

DSquaredB’s picture

Confirming that updating to 7.x-2.0+56-dev works with draggable.

zhuber’s picture

Priority: Normal » Major

I'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).

zhuber’s picture

Priority: Major » Normal
betoscopio’s picture

Confirming the solution with 7.x-2.0+56-dev version using draggable handles and not working with weight options.

purvimehta’s picture

Hello 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

iStryker’s picture

I can confirm this is an issue in the latest +60ish dev

kristin.e’s picture

I can also confirm draggable option not working for +64 dev.

cpa2client’s picture

I can confirm this problem, handles or weights do not change sort order.!!!. Any ideas of how to fix this.

chasingmaxwell’s picture

I'm attaching a patch which should fix this. I'm simply reordering the array by weight before iterating over the items.

chasingmaxwell’s picture

Status: Active » Needs review
t2000k’s picture

#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 :-)

iStryker’s picture

Thats how drupal works if you have 3 things, then the range is -3 to 3. so the first numbers are -3, -2, -1.

ron_s’s picture

Status: Needs review » Reviewed & tested by the community

I can confirm that #12 fixes the issue for me. Thanks for the patch.

iStryker’s picture

I 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.

iStryker’s picture

Status: Reviewed & tested by the community » Fixed

Tested patch myself and it fixes the problem.

kristin.e’s picture

Version: 7.x-2.x-dev » 7.x-2.1

Hi, 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.

kristin.e’s picture

Status: Fixed » Active
iStryker’s picture

Status: Active » Fixed

Kristin.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.

ron_s’s picture

Version: 7.x-2.1 » 7.x-2.x-dev

kristin.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.

kristin.e’s picture

Thanks 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.

iStryker’s picture

Hi 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.

kristin.e’s picture

Sure will do - makes sense. don't want to clutter.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

David_Rothstein’s picture

This commit seems to have broken some things - see the linked issue for a fix.