Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to deal with multiple lists with their own todos? #5

Open
bradbajuz opened this issue Apr 8, 2021 · 0 comments
Open

How to deal with multiple lists with their own todos? #5

bradbajuz opened this issue Apr 8, 2021 · 0 comments
Projects

Comments

@bradbajuz
Copy link

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:

  def sort
    params[:todo].each_with_index do |id, index|
      Todo.where(id: id).update_all(position: index + 1)
    end

    head(: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?

@guillaumebriday guillaumebriday added this to To do in Board Sep 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Board
To do
Development

No branches or pull requests

1 participant