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!
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.
Thanks for the tip! Yeah i'll have to do something like that i guess. It just seems weird to me that there isn't any method that just fires once after sorting is complete. I can definitely see the use for the update() method, but it would be handy to have a method that only fires once after a completed sort, no matter the amount of groups. :)
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.
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!
For now i resorted to using the stop() method, which isn't ideal, but at least it never calls the ajax php script twice.