The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Jquery Sortable: update method

  • This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
  • #35310

    Hello people!

    So i’m working on a project which involves sortable items with connect lists. No worries at all setting it up, but i’m wondering a little bit about the update method.

    From what i’ve seen searching the web, most people use the update method for storing the new order with an ajax post, however, when i drag an item from one of the “panes” to the other pane, the update method runs through twice. One time for each “pane” so to speak.

    So my question is, wouldn’t that mean that my Ajax call will be run twice as well (which i guess isn’t THAT big of a deal since i’m planning to just store the new order-values in a cookie), but it still doesn’t seem like very optimal coding, or is it just me being fundamentally retarded? :)

    Hoping some of you bright brains out there might enlighten the situation for me!

    JSFiddle here:
    (I added an alert() in the update method for good measure)



    You are getting two callbacks because of the two different groups. One is firing from the first group and the second from the second group. I think a simple flag should do the trick – basically, when the first callback fires, check to see if a flag is true, and if it isn’t, set it to true, then run whatever callback code you want. I’d use a “setTimeout()” for maybe 1 second to clear the flag again. If you need to see some code, just hollar.


    Actually I think it makes sense that both fire off an update. Look at it from the server side perspective… you’ll need to make a change to both lists in the database.

    John Watson

    If you need to send all changes at once, you can combine remove and receive events and in each collect data into one array which then you can post as json on the stop event. Here is the solution:

Viewing 4 posts - 1 through 4 (of 4 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.