You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've been trying to wrap my head around getting the sortable to work with multiple lists with todos and serializing. Similar to how jQuery Sortable works.
Todos in each list will always begin at 1 and increment as todos are added and decrement as todos are removed.
For example:
Todo List One has three todos
Todo 5, position: 1
Todo 1, position: 2
Todo 9, position: 3
Todo List Two has five todos
Todo 5, position: 1
Todo 1, position: 2
Todo 9, position: 3
Todo 17, position: 4
Todo 2, position: 5
In the current stimulus-sortable examples, this is how it works for only one list. Once any additional lists are added, the todos continue to be treated like they all belong to one list, so if there are 8 todos (three todos in List One and 5 todos in List Two), the respective positions will be 1-8.
A custom sort route would be needed as a collection that takes serialized data.
The sort action will do something like this:
defsortparams[:todo].each_with_indexdo |id,index|
Todo.where(id: id).update_all(position: index + 1)endhead(:ok)end
But I can't for the life of me figure out how to get this to work with stimulus-sortable. How do I get serialized data from the stimulus-sortable controller to my sort action?
The text was updated successfully, but these errors were encountered:
I've been trying to wrap my head around getting the sortable to work with multiple lists with todos and serializing. Similar to how jQuery Sortable works.
Todos in each list will always begin at 1 and increment as todos are added and decrement as todos are removed.
For example:
Todo List One has three todos
Todo List Two has five todos
In the current stimulus-sortable examples, this is how it works for only one list. Once any additional lists are added, the todos continue to be treated like they all belong to one list, so if there are 8 todos (three todos in List One and 5 todos in List Two), the respective positions will be 1-8.
A custom sort route would be needed as a collection that takes serialized data.
The sort action will do something like this:
But I can't for the life of me figure out how to get this to work with stimulus-sortable. How do I get serialized data from the stimulus-sortable controller to my sort action?
The text was updated successfully, but these errors were encountered: