Forums

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
    Posts
  • #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: http://jsfiddle.net/pfQkZ/1/
    (I added an alert() in the update method for good measure)

    Cheers!

    #91559
    Mottie
    Member

    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.

    #91608
    Mottie
    Member

    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.

    #176178
    John Watson
    Participant

    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: http://r2d2.cc/2014/07/22/jquery-sortable-connectwith-how-to-save-all-changes-to-the-database/

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