sethvargo
sethvargo

Reputation: 26997

rails and jquery sortable

im trying to implement a nice gui for organizing posts. i want to use jQuery UI's sortable so the user can drag/drop. i have a column for each post in my database "display order" that i sort by

how can i effectively translate what jquery does to the display_order columns in my db?

Upvotes: 4

Views: 1601

Answers (1)

Nikita Rybak
Nikita Rybak

Reputation: 68046

One step at the time

  1. Attach onchange handler to ui sortable.
  2. Each time order changes, loop through your elements and recalculate their positions.
  3. Save new position data with ajax request, or add a 'save' button for the user to do it later.

edit
but how do I also get the unique IDs
See #2.

var rank = 1;
$('.my-element').each(function() {
    $(this).find('input.rank').val(rank++);
});

As for 'expensive', that's your choice. You can add 'save' button, as I noted above.

Upvotes: 4

Related Questions