Scriptaculous Drag & Drop

January 23, 2008

Ok, im attempting the scriptaculous drag & drop that updates the list elements in the db via ajax.

I was using this tutorial from zenofshen.com as a refernce for the db update.

The only thing is that i think that method is a bit ineffcient by updating ALL the element rankings. I thought of only updating only the elements that had changed. ie: Get all the elements after the one that had just been re-positioned and increment their rankings. Then update the re-positioned element’s order with its new value.

This would shrink the amount of queries to (x of elements) to just 2. The only problem is, i don’t know of an efficient way of doing so. The onChange option is good cos it give you the repositioned element as the function parameter, but! it is invoked after every change of the list (ie: during the drag & over, not when the drag & drop is completed). I thought of using the onUpdate -> serialize method, and referencing a variable that had the previous state of the list. Therefore you could figure out what element had been repositioned and the update from there. The only thing is, to get that original state, u need to use serialize which wont even parse using toQueryParams… There must be something im missing! Gah

Advertisements

One Response to “Scriptaculous Drag & Drop”

  1. fabilo Says:

    After sleeping on it, i realised that it would take just 1 update after a drag & drop to fail, and that would cause the entire ranking/order to be out of sync for the rest of the execution. So i guess the robustness of updating all the fields is a good compromise for the little ineffciency of updating all the fields.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: