Looking at the archives, people have asked this before, but I can''t find a proper answer: How do you get sortable_element to return the dragged (moved) element? I know I can compare the list of elements before and after, but I need to know exactly which element was moved. The problem with comparing the list before and after is that if an element is dragged one element forward or backward, it''s not clear which element was actually dragged. For instance, suppose the ids are 0, 1, 2, 3, 4, 5 Before: 0, 1, 2, 3, 4, 5 After: 0, 1, 2, 4, 3, 5 I can''t tell whether element 4 was moved forward or element 3 moved backward. This is very important for the app because the list represents a schedule of tasks ordered by time. When an element is moved, its start time needs to be adjusted based on the element that occurs before it in the updated list. Given the simple example above, its impossible to tell which element''s start time to update. Any thoughts? Am I approaching this completely wrong? -paul -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails-spinoffs/attachments/20050923/083b6969/attachment.html
On Sep 23, 2005, at 2:02 PM, Paul wrote:> How do you get sortable_element to return the dragged (moved) > element? I know I can compare the list of elements before and > after, but I need to know exactly which element was moved. The > problem with comparing the list before and after is that if an > element is dragged one element forward or backward, it?s not clear > which element was actually dragged. > >I would love to know how to determine this also, but I suspect it might not be possible. Right now I have a routine that takes the list and moves each one in turn to the top... but it frequently "breaks," as more than one element starts thinking it''s #1 in the list! It''s really, really frustrating. I''ve tried to track it down several times but given up, as I can''t really determine where the problem might lie. And anyway, it seems unwise to need 10 database queries for each AJAX drag in a list of 10 items, from a performance perspective. If anyone has any suggestions or has beat these problems before, I''d love to hear about it. -raymond -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails-spinoffs/attachments/20051002/d5f678d2/attachment.html
I think this''s actually come up on the list before. I''ve suggested: <script type="text/javascript"> function getIndex(li) { var items = li.parentNode.childNodes; //get list for(var i = 0; i < items.length; i++) { //traverse list if(li == items[i]) { //look for match alert(i); //display position (0-based) break; } } } </script> <ul id="parentList"> <li id="childItem_1" onmouseup="getIndex(this);">item 1</li> <li id="childItem_2" onmouseup="getIndex(this);">item 2</li> <li id="childItem_3" onmouseup="getIndex(this);">item 3</li> </ul> (I actually do this via Behaviour, but you should get the point.) On 10/2/05, Raymond Brigleb <ray@needmoredesigns.com> wrote:> > On Sep 23, 2005, at 2:02 PM, Paul wrote: > > How do you get sortable_element to return the dragged (moved) element? I > know I can compare the list of elements before and after, but I need to know > exactly which element was moved. The problem with comparing the list before > and after is that if an element is dragged one element forward or backward, > it''s not clear which element was actually dragged. > > > I would love to know how to determine this also, but I suspect it might > not be possible. Right now I have a routine that takes the list and moves > each one in turn to the top... but it frequently "breaks," as more than one > element starts thinking it''s #1 in the list! It''s really, really > frustrating. I''ve tried to track it down several times but given up, as I > can''t really determine where the problem might lie. And anyway, it seems > unwise to need 10 database queries for each AJAX drag in a list of 10 items, > from a performance perspective. > If anyone has any suggestions or has beat these problems before, I''d love > to hear about it. > > -raymond > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > > >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails-spinoffs/attachments/20051003/0356d3b4/attachment.html