1

I am building a todo list application for one of my projects and I am creating multiple todo lists dynamically from the database and each todo list will have multiple todo items. The items will be constrained to their own list and will not be able to be connected to another list.

I've done a single sortable list in jquery before, but I am having a hard time wrapping my head around how to write DRY code, so I am not repeating myself for each new todo list a user creates. Since the jquery code will have to figure out how many todo lists there are, and then manage each one.

Anybody know how to go about doing this or could you talk through it with some pseudocode or an example would be great.

Thanks

3 Answers 3

2

What's wrong with using the jQuery sortable plugin and just doing something like

$(document).ready(){
    $('ol, ul').sortable(); //make every ordered and unordered list sortable
});
Sign up to request clarification or add additional context in comments.

1 Comment

good call, then I can just grab the id of ul so I know the parent...thanks!
1

two other options (in general):

  1. create the sortable group by id:

    $("#list1, #list2, #list3").sortable({ connectWith: "#list1, #list2, #list3" });
    
  2. create the sortable group by class:

    $("#list1, #list2, #list3").sortable({ connectWith: ".transfer" });
    

    (.transfer is the class, just assign this to all your lists in your html.)

Comments

0

To be DRY in jQuery, you want to write plugins, or use an existing plugin such as Tablesorter.

2 Comments

Thanks for the response, but using Tablesorter has nothing to do with my question does it? I agree a plugin, would be a nice solution, but I am looking for how I should write it.
perhaps you could provide more information. It sounded like you were looking to do multiple sortable todo lists. A few people thought that you were looking for a sortable solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.