In taxonomy.admin.inc it handles draggable sorting with hierarchy. It is fairly complicated as it is solve with 200 lines of code.

Their method
solves #1551230: Add pager support for DraggableViews tables, and multiple issues like

  • It grabs the data from the page before and the page after.
  • It makes sure the top and the bottom of the page ends in a root (depth of 0).
  • A range of -total_items to +total_item, but does break when there is a pager.

prevents recurring issues of #1780498: Row weights values are all the same.
and dissolve #1901192: Row weight values range should be the same as what gets save to database

It might or might not help come up with a solution for
#566332: Grouping DraggableViews

Now the structure does break how we store stuff in the database.
Currently stored like this (with hierarchy)
entity_id (as a letter) - weight - parent (as a letter instead of a number)

A - 0 - 0 
B - 1 - A
C - 2 - A
D - 3 - 0
E - 4 - D
F - 5 - E
G - 6 - D

How taxonomy stores

A - 0 - 0
B - 0 - A
C - 1 - A
D - 1 - 0
E - 0 - D
F - 0 - E
G - 1 - D

another way of express this
Current - Draggableviews way
ID Weight:Parent

A 1:0
   B  2:A
   C  3:A
D 4:0
   E 5:D
      F 6:E
   G 7:D

vs

A 0:0
   B 0:A
   C 1:A
D 1:0
   E 0:D
      F 0:E
   G 1:D

I believe this solution should be explored.
Thinking ahead, an update_hook() might be need to update the database.

Comments

iStryker’s picture