johnny / jquery-sortable

A flexible, opinionated sorting plugin for jQuery
http://johnny.github.io/jquery-sortable/
Other
1.52k stars 441 forks source link

Help wanted: Saving re-ordered structure #250

Open ghost opened 6 years ago

ghost commented 6 years ago

Hi,

I have jquery-sortable working fine in my site page now, however, and sorry if this is a bit of a silly question, but how do I go about saving / getting access to the new structure once the user has done their dragging and dropping?

I am using it for the re-ordering of menu items, and the initial structure on page load is from a parent/child database table.

What I need to do is, on the press of a Save Changes button, update the database table with the changes, or re-create the table contents if needs be from the new UL / LI structure.

I have added to the LI's custom attributes with the parent/child ID's.

How would I do this please?

Thanks in advance.

ghost commented 6 years ago

Just as an addition to the above, I have now tried adding the serialization demo code in and it is showing in the PRE tag I have added changes as a JSON list when I move item about, but unless I have missed something / done something silly, the parent ID's are staying the same in the data-id attribute?

Are the move from one parentID section to another something I need to handle myself?

Magniveo commented 6 years ago

You can write in Ondrop method your jquery method for saving the sorted table in DB may be.

DigitalDesignerOnline commented 6 years ago

I used the jquery sortable to create a sortable list where as when you drag the rows the number updates as well, from there when you save the data it updates the database tables and returns the new results on the next page, would this be a suitable solution? May I assist with this issue?