Andreas Lyngstad
Andreas Lyngstad

Reputation: 4927

Rails 3 Jquery Ajax how to insert a new element in the propper place

I have a list of tasks that sorted by the due date. When I create a new task it gets appended to the list.

Problem: I really want the new task to appear in the right place in the list of tasks.

When I make a task for monday, I want it to get inserted after the other monday tasks and not get appended to the end of the list.

I've tried to add a data-due attribute to the tasks and loop trough the values.

But I find this soloution to complex.

Do you know a simpler soloution?

Upvotes: 0

Views: 200

Answers (1)

Solomon
Solomon

Reputation: 7023

If you set each of the list items to have an html id property

<li id="task_123">

you can figure out which record to insert before / after using rails, and then use jquery to just insert at the correct place.

Upvotes: 1

Related Questions