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 jque开发者_如何学JAVAry does to the display_order columns in my db?
One step at the time
- Attach onchange handler to ui sortable.
- Each time order changes, loop through your elements and recalculate their positions.
- 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.
精彩评论