In a given situation I am facing, there is a long list of columns represented by <li>
elements in two <ul>
lists. On the left side are all available fields that can be selected by users, while on the right side users drag and drop desired fields from the left list to build an ordered list of columns for a dynamic report.
By using the JQueryUI Sortable()
method, I have successfully created lists for dragging and dropping these column elements as needed. The functionality works flawlessly when moving content from the left list to the right, allowing users to order the columns themselves.
However, if a user decides not to include a previously added column and drags it back from the right list to the left, I would like the item to return to a specific pre-determined position within the left-side Sortable()
list, rather than being placed below where it was dropped.
What is the best way to address this requirement? Should I utilize a JQueryUI Sortable()
object for the container of columns on the left side and reorganize the data upon dropping, or is there a more suitable JQuery tool for this task? If opting for defining the left-side list as a Sortable()
object, how should I adjust it to ensure proper reordering post-drop operation?
I have used this JSFiddle to set up the basic mechanics of the lists. While the right-side list functions as intended, I aim for the left side to maintain a sorted order based on a specified value for forced sorting. For instance, in this example, the left side should consistently sort based on the data-sort
attribute defined in each <li>
.