Multi List Drag and Drop

I was playing with Tim Taylor’s excellent List Drag and Drop javascript and came across the multi list version by Ben Levy.

I made a few modifcations to it adding a “trash” container so that items that are dragged and dropped outside of an area are not lost.
I also added some php to make it persistent by saving the layout inside of a mysql database.

You can see an example and check the php source.

Something like this would be cool for CMS layout editor.

Updated again (15 July).
I have put in an example of updating the database using SAJAX so user is not required to click submit to update the layout it is done automatically when they ‘drop’.
Added a group feature so you can group certain lists together and cannot drag and drop to a list outside of the group.

Updated again (18 July).
Made the php more secure, was not concentrating very hard on that part when I made it!

227 Responses to “Multi List Drag and Drop”

  1. Tom Westcott Says:

    No longer need a trash container added the bounce back feature.

  2. Sebastian Moser Says:

    Incredible what you created. First I wanted to change the Ben Levy’s script to do exactly what your script does (trash can & saving the new order of the elements), but because of my lack of knowledge of this parts of JavaScript, I had to look and found your solution.

    I use it for a broadcast-distribution-software for a local TV-station in Austria. With the drag&drop-functionality, you can choose the broadcasts you need for a certain area and sort them in the way you want, then you click “Distribute” and a complete tv-show is created and automatically distributed to the region-specific network.

    Quite interesting and probably an unexpected way to use it… ;)

    Thanks for your work, without you I really would have problems… ;)

  3. Ulrich Says:

    Tom,
    that is great work. If we could convince Tim to implement something like dragging a copy of a list item.. and I can die a happy man.

  4. Tom Westcott Says:

    Dragging a copy? do you mean cloning the item when you start to drag it giving you two copys?

  5. Ulrich Says:

    Tom,
    yes I meant cloning.

    I am building an interactive team selection component for my clubs website and players can play in multiple teams each weekend… So I need be able to assign same player to multiple teams…

  6. Ulrich Says:

    Tom,
    The drag drop library of Walter Zorn can do cloning for images.. maybe this you can find some inspiration pointers how to do this for layers http://www.walterzorn.com/dragdrop/dragdrop_e.htm

  7. Dipesh Says:

    Hi,

    Great work. Nice script!

    I am trying to do the following:

    i have tables laid out horizontally (for example say there are 5 tables). Now tables have the following numbe of rows:

    table Rows
    =========================
    table1 3
    table2 4
    table3 1
    table4 3
    table5 5

    I have to give user flexibility to:
    1) I need to drag the whole table i.e. exchange position of table1 and table2 etc.

    2) I need to exchange rows in the table itself.

    3 )I need to exchange rows from one table to another.

    Is it easy to do this? How should i go about this? I am not DHTML pro, basically system programmer.

    Any pointer to solve this will be highly appreciated.

    Regards,

    Dipesh

  8. Tom Westcott Says:

    Updated again.
    I have put in an example of updating the database using SAJAX so user is not required to click submit to update the layout it is done automatically when they ‘drop’.
    Added a group feature so you can group certain lists together and cannot drag and drop to a list outside of the group.

    Ulrich,
    That sounds like a very cool feature to able to have. I think it can be done fairly easily I will have a look into it.

  9. Tom Westcott Says:

    Dipesh,

    You could maybe implementing the table swapping as the parts are swapped here:

    http://kiwi-interactive.com/experiments/inlineEdits/drag.html

    to swap rows in the table(s) I am not sure you try implementing them as lists instead and swapping them that way?

  10. Tyler Leeds Says:

    Super cool mod Tom. Now it does everything I wanted. You just made my day :-)

    Thanks for the code.

    Cheers
    Tyler Leeds

  11. ulrich Says:

    Tom,
    seems that someone manged to break your 1st example… no items left in the lists….

  12. Tom Westcott Says:

    Thanks for heads up, I guess that can be done by sending a post with no data ak :/

  13. Tom Westcott Says:

    Made the php more secure, was not concentrating very hard on that part when I made it!

  14. Gary Weisserman Says:

    So I’m playing with a version ripped from Ben Levy’s example, and I’m trying to figure out a way to pass the position of each element as a regular form element:

    http://dewey.umflint.edu/drag_and_drop/

    I can’t use ajax for this; I just need a regular form parameter (or set of form parameters) that contain the info.

    Any ideas? I sure could use them! (-;

  15. Tom Westcott Says:

    Hey Gary
    Here how my version achives this

    When the user clicks the submit button the onclick event calls the javascript function getSort() this function calls a function in the dragdrop.js file I added called serData() basically it returns a formatted string of the order of the elements in the diffrent lists. This string is then loaded into the hidden form field called “order” so it is passed a long in the POST to the php script where the hidden field is then parsed by the php function parse_data() to return a usable array.

    Hope that helps!!

    – Tom

  16. Gary Weisserman Says:

    Hi Tom–thanks for the tip. I tried it, but to no avail (!). Well, some avail, actually. If you go to the page

    dewey.umflint.edu/drag_and_drop/

    and click the button, it DOES show the hidden input field parameters–it’s blank, with commas delimiting each entry, but with nothing to delimit. It’s very strange, like there’s data that’s supposed to be passed there. Am I doing somethign wrong? Any ideas? I’m growing despondent and have taken to randomly throwing variables around to see what’s what …!

  17. Tom Westcott Says:

    Hey Gary,

    Looks good the serData() function uses the ID tags of the li element as the name for the items add these to your list item and should should be good eg

    <li id=”fg”> Fred Goodman </li>

    If you dont want to use the id and instead want to use the list item name change this line of code in serData()

    string += items[i].id;

    to

    string += items[i].innerHTML;

    Good luck!

    – Tom

  18. Gary Weisserman Says:

    Tom, you are da man! Seriously, thanks–this helps a lot!

  19. John Morton Says:

    Tom, I also want to add my thanks for this. I’m still trying to figure out how I can use it, but it’s really cool!

  20. Juan Says:

    This is SO AWSOME!
    http://www.dlplp.com/v6/test (login: dlptest // pass:0123)
    I have been working on this for few days now and I saw ur post after i had made a post on Tim Taylor’s Blog so that’s how I got here..
    well..what I wanted to add here was: You alredy got the functionality of the tables to be dragged and dropped PLUS: (the big one) you made it save into a database and even better automatically..Now my question to you (thats if u check my page out) is, ok adding to the drag and drop funtionality can it be done so that you can also edit content inside the tables… and save them automatically to the database too?
    And a HUGE step, making like a style page, in which users could go in and select an order of the tables to be displayed like..
    some thing like : adding tables/deleteing, moving (up/down/left/rigth) between other category tables. or soemthing..
    it might sound like a lot but don’t it sound so cool?
    lol

    – Juan

  21. Adam Hawkins Says:

    I seems as if javascript is back in the limelight with the recent ajax coverage and this appears the be the end of the trail and the leading edge of tech. im looking to take this further with standard ui like ctrl click copy drag & shift click move drag - also ctrl click multi select and shift click rnaged select of items for ajax interaction
    has anyone come across any of similar work with javascript drag with which to build on or is the the end of the trail
    btw - this is shit hot and i think its tech that flash has been teasing us with for ages but never delivered.
    any pointers appreciated.
    A

  22. Joris Says:

    Hi,

    This script is exactly what I needed. But I am trying to make nested draggable lists, so I need to be able to set a handle. I tried editing the source a little but I didn’t manage to find a way. is there anyone who could help me along a bit?

    -Joris

  23. Tom Westcott Says:

    Juan, I think you can use part of Tim Taylors javascript library to do inline editing? (http://tool-man.org/examples/edit-in-place.html).
    As for the other part I think you need to mess with php some more.

    Adam, it looks like you have got your work cut out making something that interactive, but it sounds very cool please keep me updated on how you get along with it.

    Joris, how do you mean set a handle ? You only want to drag items inside the lists that are nested?

    – Tom

  24. Juan Says:

    I think what Joris means is having the functionality of been able to not only drag The lists but also drag the complete set to another place.
    Lets say you have three colums: Left, Middle, and Right
    Left has 2 dragable lists.
    Middle 3
    and Right only 1
    The lists inside all of these can be dragged between the lists.
    But what I think he means is Been able to move Middle to Right or left
    Left to Middle or right. or Right to middle or left..
    Bringing with it all the lists inside of it… (am I making sense?)
    ===============

    Another thing, I have tried to do the Inline Editing inside your code but the function:
    ===========================
    window.onload = function() {

    /* var list = document.getElementById(”left_col”);
    DragDrop.makeListContainer( list, ‘g1′ );
    list.onDragOver….
    ============================

    that is part of your java cancels the funtionality of being able of drag items and editing them from Tim Taylor’s scripts:
    I’ also found this other great script that lets you save your edited content from a table into the database somewhat like what you did with your script to send it to a DB with AJAX.
    http://labs.revision10.com/experiments/dat/dat_example.php

    and I have been working on it but I’m not a big expert on PHP and Java just yet.. so I’m playing around with things at the moment.
    Here’s my sample of what I’m working on with your script:
    http://www.dlplp.com/v6/test/dd.php
    and the one for editing fields:
    http://www.dlplp.com/v6/test/edit_fields.php
    so I still got a long way to go.. specially for me cause I’m just not that knowledgable with PHP and JS

  25. Juan Says:

    Nevermmind, the Problem was fixed… it was the window.onload = function() {
    function because it was loading two at a time, so it blocked the other..
    Now I’m trying to get it so that it edits the fields and saves them automatically.. but no one seems to help.. so I’m like so stuck..

  26. Ben Says:

    In response to the person who wants nested trees to be sortable, I came across an interesting script. It’s still rather beta, but it might give you an idea of how to go about it.
    http://mir.aculo.us/stuff/test-tree/tree.html

  27. Ben Says:

    Also, on Tim’s website he had an example of sorting items in two dimensions, I believe with his scripting he did it simply with a float:left to make the elements bunch up together. I’ve tried a few ways to get it working with this script, but to no avail.
    Ben

  28. Jeroen Sen Says:

    Wow! The dragging and drop between lists is a very cool feature. I want to use this in a cms that I’m constructing at the moment. I’ve implemented a solution of the (original) edit in place sortable lists by Tim Taylor, and was wondering if these two awesome scripts can be combined. Since I’m not that kind of a javascript expert (adding a the feature that the edited text on the button in the example could be saved, cost me all day :’( ), is there anyone who has any idea of how to acomplish this?

    Further more, I’m wondering if it is possible to add a second layer to the edit in place feature. This would make it possible that not only the text on the button (as shown on the button) but also the target-link of the button would be editable on the same page. My idea is that selecting these editable fields would happen with a single or a double click. (Clicking the button once would result in editing the text on the button, clicking twice would result in editing the a href of the button.)

    With this added feature it would be possible to make an all editable sortable list. That would be a great feature for editing menu’s in cms-es everywhere! Ideas? Anyone? :)

    (notice, I’m posting here, because of all the idea’s in the previous posts, thinking it would be better to group all the idea’s)

    Greets,

    Jeroen

  29. Omar Says:

    Hi, I’m trying to get the drag/sort code working with lists that have overflow:auto or overflow:scroll. It seems when you set these styles on (to force overflowed content to be scrolling content) a or the lists items tend to blow out of the boundary created by the or width and height properties (at least in IE, in FFX the boundary sticks, but then when you drag and sort the list items flicker and become offset in an obstrusive way). I’ve narrowed down so far to the

    createGroup : function(element) {
    var group = new _ToolManDragGroup(this, element)

    var position = “”;//ToolMan.css().readStyle(element, ‘position’)
    if (position == ’static’) {
    element.style[”position”] = ‘relative’
    } else if (position == ‘absolute’) {
    /* for Safari 1.2 */
    ToolMan.coordinates().topLeftOffset(element).reposition(element)
    }

    return group
    },

    That is causing this undesired effect.. these ‘repositioning’ commands.. any help would be appreciated.. i’m still gonna try to debug this

    Thanks.
    Omar

  30. Bob Says:

    Hi Guys
    I was wondering , that if it is possible to do a copy and drop rather then a drag and drop, what I mean is that rather then moving the object and dropping it to some place, can we leave a copy of the original there and basically paste an instant on the drop place ?

    Thanks

  31. Bob Says:

    An example for my previous comment would be, like chossing and picking up an item for a shopping cart .

    Thanks

  32. Ben Says:

    Check out
    http://script.aculo.us/demos/shop
    for an example of a shopping cart

  33. Ben Says:

    Any way to unregister a list? I’m dynamically adding material to my list and I’d like to be able to unreigster the list so I can re-register it with the new material. I run into problems if I just re-register the same list. (IE crashes).
    By register, I mean:
    DragDrop.makeListContainer(parentHolder,’s1′);

  34. Bob Says:

    Thanks Ben
    But it’s using Ruby ? And I am not familier with it, how difficult it is ? Any Ideas ?

  35. Ben Says:

    Ruby on Rails is sweet, I suggest you learn about it if you have time. It is not difficult to use at all. Those tricky Japanese.
    Anyway, you don’t *have* to use Ruby, just check out the source code and work your way through it, you’ll be fine.
    Check out how to do a drop on that same site (script.aculo.us find the documentation) and it shouldn’t be too difficult to do… just create objects that interface with the drop, and call a script on the onDrop event that creates a copy of the dropped element.

  36. Ben Says:

    Okay, seriously, does anyone know how I can make a sortable group with the script on this page, and then add another element to that sortable group?

  37. jadwigo Says:

    I like this implementation..

    one little detail though: your empty ul.sortable elements don’t pick up list elements.. maybe you should add something like “ul.sortable {min-height: 1em;}” to the css, or else all your listitems will end up in one list.

  38. Ben Says:

    okay, I still haven’t figured it out. Any hints on how to unregister a draggable? I have:
    DragDrop.makeListContainer(eNewSort,’s2′);
    and now I have added a child element to eNewSort, so I want to unregister the list container and redo the it. Come on please? Any help?
    Ben

  39. jc Says:

    hi all,
    firstly i just like to mention that this script is pretty cool.
    anyway what im trying to do with this is extend it so that I can have lists within lists. has anyone out their managed to achieve this?
    I think Joris was posted a similar question.
    thanks in advance.

    so it would look something like this, where i can drag items in and out of innerurl.

    Seven
    One
    Six

    One
    Two

  40. Ben Says:

    Yes, JC, I have a script that does that, I’ve been working on several alternatives. Feel free to e-mail me at nefiga@hotmail.com. Now I wish someone would answer my damn question! :)

  41. MK Says:

    Hi,

    Great Script, only issue i am facing is how to make drag item to auto scroll browser window.

    thanks.

  42. mark Says:

    nice work. just wondering if you’re going to develop this further.
    was hoping you could help me with your codes.

    see, i want to add a handle, so that dragging will only happen when i mousedown on a particular place inside the list and prevent dragging when highlighting the text inside. cant seem to find how to integrate tool-man handle with your script

    thanks

  43. Jonathan Says:

    I really like this script!

    I am having a little problem, though. First of all I changed my mysql ‘item’ field to text instead of varchar. (Maybe this is where it goes wrong).

    The problem I’m experienceing is that list items containing line breaks or br-tags doesn’t get saved to the database for some reason.

    If anybody wanna take a whack at this my adress is http://www.twotype.se/dd/dd.php

    Cheers.

  44. Jonathan Says:

    Never mind! Camino got buggy on me….

  45. Christopher Says:

    I’ve encountered a strange situation (bug? if you will.). When I wrap the lists into their own tables (for formatting purposes) and those tables are in another table (for page layout) the alignment seems to go off on the drag and drop. What’s strange is that it happens on some computers and not others. I’ved tried upgrading to IE 6 and it doesn’t always fix the problem and some IE5 machines work fine. I’m assuming it’s IE’s fault, but was trying to figure out a better work around. The page and lists are heavily dynamic so the use of tables throughout makes it easier to control the look and feel.

    Just to make sure it wasn’t something else on the page, I took your above example (View Sourced, Saved) and wrapped each list in a table and then wrapped the page in a table (i.e. nested tables) and it broke as well.

    Anyone else encountered this issue? Any ideas on how to overcome it?

    Ths.

  46. Mark Ireland Says:

    Like Jeroen Sen I too am interested in making a drag and drop editor for a Content/Document Manager. Here is my first attempt:

    http://www.realsimplecms.com/temp/index.html

    Ultimately I want the system to look and work the same way in .NET, Java, PHP and ColdFusionMX

    http://www.MarkIreland.com.au

  47. Chris Says:

    Has anyone figured out a way to select multiple items in the first list and drag (and drop) them all at once to the second list?

  48. FiLH Says:

    Hello,

    I’m trying to set up the drag and drop on a little complex web page, and I come to the following problem : I have put drag and drop list in a relative div, that has a left margin, and on MSIE the drop area becomes active with an offset that is equal to the left margin. So to activate the drop area you have to move the mouse to the right of the area. Of course such behaviour does not append in Firefox or Safari where every thing works perfectly well.
    Here is the code that does not work ;
    http://www.enseirb.fr/~goudal/tliste/Listes.html
    Draging from the left list to one of the right one does not work will on MSIE

  49. Jetnet Says:

    I have been playing with this script for a few hours. First off let me say this is a great script. Its a CMS programmers wet dream. There is only a few things that I can see wrong with the script. And by wrong, I mean that in the sence of I deal with stupid people, and confusing them even slightly should be considered a felony.

    That being said, let me give you an example of what I see wrong… If you have a column that is 600 px wide, followed by a break and two columns side by side each 300 px, and you have a large amount of text in each of your draggable boxes, like stories in a CMS, and you go from the top (600 px) to the bottom colums, as soon as that block leaves the column, you have to drag the block to the location where the column WAS, not is now. Remember, the story or draggable block that your moving is fairly large. So moving it outside of its parent causes the parent column to resize to a fairly small former self. Then the user has to drag the story to a theoritical location.

    The proposed solution would be to not change the size of the parent until the drop has occured. This way the user can see exactly where he/she needs to drag the box too. Now, the draw back to this solution is that if they drag something big into a small area, or any area for that matter, the area will not expand until they drop the item. The only solution for that would be the line with the arrows showing you where the drop will take place. You know what line with arrows that I am talking about?

    If you were dragging something between Item 1 and Item 2, it would look like this:

    Item 1
    >——————–

  50. Jetnet Says:

    Whoops. Looks like the comment secion doesnt like less then signs. Okay, well:

    Item 1
    )——–(
    Item 2
    Item 3

    It should look like that. But with arrows.

    Anyways, what I put after that was basically I am trying to get this working today, and if I do, Ill post a link to the code and an example.

    But thanks for all your work, the script is very nice.

  51. Ignacio Says:

    Greats!!! Wow!!! Yeah!!! With Sajax!!! yeah yeah yeah!!

  52. John Says:

    Multi List Drag and Drop - It would be more helpful if you could develop clone and drag items instead of removing from the list?

    http://script.aculo.us/demos/shop

    this is a neat example i wish it was text and not image.. Any chance of implementing the above example with list boxes?

  53. Steve Says:

    Is there a way that anyone knows to just remove an element from the stack. I would like to be able to click on a link or something on the element and drop it from the list, but I am having trouble.
    Sorry no examples to show.

    Great little library by the way.

  54. D'Herbe Says:

    I also have been playing around with the script and I think it is in a very simple way, an excelent script. as the php extension.

    But I couldn’t sort a way to implement an handler like in the original script from Tim Taylor, wich in a CMS its preferable due to layer sizes.

    Thanks

  55. openlogic.biz » Cyber Dummy - Web Developer » Multi List Drag and Drop Says:

    […] Drop Filed under: DHTML/AJAX, Server Side — admin @ 3:42 pm Misc DHTL stuff Cyber Dummy - Web Developer » Multi List Drag and Drop […]

  56. Vince Says:

    Has anyone tried to make the li objects copied instead of moved? Can anyone provide direction? Where in the code should that be changed?

  57. Lucas Young Says:

    Hi Guys
    I’m new to this and would just like to have a version of the sajax example with only one list - I have a table with an ‘id’ and ‘iten’ column and I want users simply to be able to drag and drop the items into a new order without a page refresh, but when I remove the refrences to “set1″ and “set2″ from the dd example, the code just breaks. Can anyone give me some tips on accomplishing this based on the dd sajax example?
    many thanks

  58. Ryan Says:

    Well done Todd. The script worked seemlessly for me. Very pleased.

    Can you give some direction to modifying the script to drag by handle (title bar style), instead of the entire list item?

    I’ve been trying to add the BoxHandle functionality in Tim’s example at http://tool-man.org/examples/dragging.html

    Line 37 of the dragdrop.js seems to be the key…
    DragDrop.makeItemDragable(items[i]);

    I’d like to make the first div of the list item the handle.

    Your direction is very appreciated.

  59. sam Says:

    Use a global to track this

    in the window.load function write :

    var DragAllowed = false;

    then in the onmousedown event of whatever the allowed handle write DragAllowed = true;

    add var DragAllowed = false; to any other objects you do not want to allow to get dragged

    in the drag.js file find function:
    onMouseDown : function(event) {

    and wrap the entire code inside with a simple :
    if (DragAllowed){
    …original code
    }

  60. bro Says:

    Hi, I’m french.
    Thank you for this incredible mod.

    I try to use it (to make little cms) but I must drop only one item in each container… (if a container already contain an item, it must not be dropable by a second item).
    Is anybody can help me please ?

    best regards…

  61. Ryan Says:

    Thanks Sam. I think that’s on the right track, although your solution wouldn’t work.

    Even setting the DragAllowed line to “true” in the onload breaks the code when the if(DragAllowed) is put in the onMouseDown function.

    ex. in index

    window.onload = function() {
    var DragAllowed = true;

    }

    and in drag.js

    onMouseDown : function(event) {
    if (DragAllowed) {

    }
    }

    I’d really appreciate your further help though. Please contact me via my site above!

    (any thoughts Tom?)

  62. Kapil Kanojia Says:

    Hello Team / Everbody,

    I need help for Multi List Drag and Drop,

    The Multi List Drag and Drop has a functionality that is draggable by taking mouseover on whole “”, what i want is to create a handle for it, i dont want section to be draggable, i want is to set a particular area to drag that complete “”,….

    Need this desparatly please help….

    Waiting for response….!

    Regards
    Kapil Kanojia

  63. Brian Terry Says:

    Has anyone been able to do this with one verticle list and one horizontal list?

    I’m trying to create editable navigation (left, top, and bottom) where the users can drag and drop between the lists.

    I have it working, but the horizontal lists are shakey when you drag items over it, and you can only drag them to the far left place.

    Thanks,
    Brian

  64. Jim Says:

    great script, Ive been trying to figure how to tweak it just a little so that when its dragging the window will scroll as necessary.

    Any help would be really cool.

    - Jim

  65. Keller Says:

    Hi,
    I want to limit the number of items that can be dragged into a list. Can anyone think of a good way to set a max number of items a list can hold? Thanks a lot.

    Keller

  66. ghyster Says:

    Hello,

    i’ve some problems to sort a list in two dimensions, it doesn’t work as in Tim’s example. Has someone found a solution to this ?

  67. Ray Says:

    Hi,

    Great script. Downloaded to play wth it, and of course, ran into a problem. Getting the follwong errors:

    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in www\test02\dd.php on line 224

    This error occurs for line:

    235, 247, 269, 279, and points to:

    while($rw = mysql_fetch_array($r))

    Any ideas?

    Thanks,

    Ray

  68. Terry Remsik Says:

    Any chance of getting these two togther ?

    http://labs.revision10.com/experiments/dat/dat_example.php
    and yours ? that would be awsome!!!!

  69. Terry Remsik Says:

    Ghyster…. I think you will need to look at this:

    http://tool-man.org/examples/sorting.html

    Search on the page for this “Example: Sorting in two dimensions”

  70. Donald Says:

    Thanks a million man, this is utterly awesome!

    Does anyone knows how to constrain the dragging?
    I’m not a js kiddie and need some general tips..
    I’ve fiddled with the constrainVertial but that did nothing…

    Many thanks in advance!

    :: Don

  71. Leo fajardo Says:

    yaw!!anyone here knows how to make an autoupdate counter..just like in gmail..where the server can be autoupdated instantly and publishing it back to the client??please help..thanks

  72. samir Says:

    Hello,

    I what browsers do the multi list drag and drop work

    http://www.cyberdummy.co.uk/test/dd.php

    Thank you,
    Samir

  73. RM Says:

    Read back through your old comments and noticed that you removed code for deleting items…any chance you can post it somewhere?

    I need to implement a trash can feature in addition to moving between two lists.

    Thanks!

  74. Seb Says:

    Your example is that I wanted but I have a little problem.
    I would insert a handle into , how I could do this ?

    Thanl you.

  75. Greg Says:

    Great stuff! I have a couple of questions:

    Is it possible to use this script with div layers instead of ul/li ?

    Also, I’d like to change content of a layer/list when dropped in one specific draggable area?

    Thanks in advance!

  76. Markus Schraudolph Says:

    Hi Tom,

    just wanted to use the Sajax-part of your demo dd.php for my app. In my case though, it was important to know, which -Element was being dragged and what drop zone was used. The function OnDrop() in the demo having no params just was too unspecific for me.

    So I changed line 227 in dragdrop.js from
    this.parentNode.onDragDrop();
    to
    this.parentNode.onDragDrop(this.id,this.parentNode.id);

    Now the first parameter in my client-side event handler tells me the id of the -Element and the second the id of the -Element being used as a drop zone. In the PHP-Part I only have to submit this single operation to the database.

    Thanks for your great work!
    Markus

  77. Markus Schraudolph Says:

    oops, spoilt the Tags for {LI} and {UL} in my last post.
    Sorry!

  78. amir Says:

    hey
    great script
    but im having a problem. im trying to get the items into a table and its not working
    is there any chance to use instad of ?
    anyone modify that script for that?

  79. amir Says:

    another question
    how can i modify that script that instad of clicking anywhere in the box its dragging it , to put a icon “click here to drag”
    ?
    anyone has the code modified?

  80. John Says:

    Hi!
    The Multi List Drag and Drop script is great! And You’re right, that something like this would be cool for CMS layout editor. But is there a possibility of making nested lists (trees)?

  81. John Moore Says:

    Is it possible/easy to do the following: allow items to be dragged from List A to List B, without being removed from List A? I.e., working as a list of possible choices. I’d like the user to be able to drag an item from List A to List B to select it, and drag it out of List B anywhere to deselect it. This is all new stuff to me, so any examples I could find would be a great help. Thanks for the good work!

  82. phynias Says:

    i was messing around with this getting it to work with float images.

    http://turk-182.com/eMortal/admin/test.html

    i got it to work, but the only problem is that the sorting doesnt really work right. try and drag an image in between 2 others and it jumps to the beginning or end of that row. anyone have any ideas on how to make this a little more smooth like here.

    http://turk-182.com/eMortal/admin2/testSortable.php

  83. Andy Says:

    Hiya,

    reference to amir’s post, i think an additional support to have a handle (hotspot) for dragging would be great! Any life saviour?

  84. manikandan Says:

    hi, am a student and new to web application.When i open checking the user name EXAMPLE in this site in firefox, konqueror & mozilla browser its working fine but when i opened in Internet Elplorer 5 its not working.Its showing the alert message as Could not evaluate .Its fetching the data from the server and displaying in the alert message and not in the screen.Any one can give the solution.
    Regards,

  85. zoze Says:

    Guys I love that multy drag and drop you can help m to update xml file with drag drop I have test it with DB need to update xml file can anyone help Thanks

  86. Andy Says:

    Hi,

    anyone have the modification to enable a handle (hotspot) for dragging??? Aparently, the author doesnt seems to reply anymore

  87. jason Says:

    hi, if I put a input text field in the area. I can’t type anything in the textfield int firefox 1.5.01.

    The html looks like:

    images/google.gif” >

  88. xenakis Says:

    Hi guys,

    Excellent program!

    I made a little game type thing with it for fun.

    http://www.recordcorner.com/_experiments/squares/

    One thing I have noticed is that if I put tons of squares, the algorithm because much much slower.

    Any way around this to keep it fast?

  89. sven macolic Says:

    hi!
    i have an issue with multi drag and drop which i cant figure out how to solve it…
    the problem is next…
    i made an ul id with li inside..
    so i can drag those li tags..ok till now..
    in every li tag i added a new ul tag with another id and with li tag inside again..
    now what happens..
    the serialization of the li tags into the first ul take all childnodes and the li tags from the second ul inside…
    i tried with some lite barrers like to check the className before serialize them but the getElements ByTagName doesnt recognize the li tag that i drag and drop it????
    any help appreciated..
    thanx in advance..

  90. Nolan Amy Says:

    I have what I think is a quick, easy question:

    How do you keep from highlighting the text on the page while dragging?

    event handling, like stopping propagation? i kinda tried that.

    Just a tip on where to look for an answer would be really helpful. Thanks a lot.

  91. jeevanantham Says:

    Hi guys,

    I need swap table columns on drag and drop.

    Please let me know the way.

    have a nice day.

    jeeva

  92. Damon Says:

    If you take the original multilist example, http://neb.net/playground/dragdrop/, and you put the second list into the first list (nested), you’re then able to drag the entire second list into various positions of the first list. Individual list items in the second list are no longer draggable though … it’s the whole list or nothing … can anyone make this work? Basically the same as some other people have been asking for … hierarchy, tree view, drag and drop between nested list items, all that good stuff.

    Here’s an example that uses XML/XSL, but it only works in IE…
    http://www.15seconds.com/issue/020424.htm

    Clicking on the demo does not work for some reason, but you can download the code, and open it i IE, and it works really well. I’d much rather have this kind of functionality without the XML/XSL….

  93. xenakis Says:

    I have been working on sorting in two dimensions example from Toolman - http://tool-man.org/examples/sorting.html.

    In my version, I want to include a checkbox inside the boxes so that a use can choose the option. In all the browsers except Safari, this works fine. The problem in Safari is that the checkboxes aren’t clickable. The cursor stays in the move position. In the other browers I guess the checkbox field overrides the movable aspect of the box and remains clickable.

    Does anyone know how to fix this in safari???

    I thought about alterating the javascript so that only part of the box is movable, but I don’t really know what to change in the javascript code to do this.

    Here is my example:

    http://www.recordcorner.com/sorting_test2.php

    Thanks!
    xenakis

  94. hui Says:

    Great work!!! Must say Thank you!!!

    A big improment from the multi list version by Ben Levy.

    Just found 1 problem:
    When I set the style of the to be float:left; (coz i want the elements in the list to show horizontally), the movement of the element within the same list would go wired.

    It will be of greate help if this can be fixed.

  95. Jason Says:

    Could someone tell me if it is possible to put a table in one of the list items and make the table only dragable by its header and not it’s content. Thanks for the help.

  96. james Says:

    Has anyone tried using this with indented lists? I have to make an interface to allow the reordering of menu elements but the menu can have multiple levels of sub-menus, so indented lists would be appropriate I think. If you have any tip or any other suggestion it would be greatly appreciated.

  97. grd Says:

    Hi
    Could anyone get me a sample code of how to use Tim’s (tool-man.org) inline editing in our code.

    Thank You

  98. Dav Says:

    Tom, GREAT SCRIPT!!!!!
    I am trying to implement it, but wanted to drop the element in the next container without removing from the first container.
    I mean clone on drag start.
    How to do this?

  99. Xnuiem Says:

    Anyone figure out how to make the page scroll when an item is being dragged?

  100. Tony Covert Says:

    Did anyone ever have any luck finding out how to get a hotspot (drag handle) working with Tom’s example?

    If you have can you please share?

    PLEEEEZE :)

    -Tony

  101. Tony Webber Says:

    Hi, great work. I really need to do this in classic ASP. Do you know if there is an example of such a thing? Many thanks for any guidance you can give me.

    Tony

  102. feha Says:

    I love this

    Will try to test with my CMS …
    http://www.vision.to/CMS_BE/Home/

    Btw what are conditions of use, license ?
    Any donation info ?

  103. Julien Says:

    I’m trying to use this excellent script to customize a page in edit mode. But there are some bugs when you are trying to move an object relative big to a different box. the bugs are following :

    - the box do not always take the dimensions of my object, even if your are over it

    - Sometimes a bigger box wich is over an over smaller box, will be bigger to welcome my item, and in this case I cannot put it in the smallest box ….

    if you don’t really understand my problems, try yourself :

    http://dev.sportanddev.org/en/exemple/

    does anyone have a good slution to fix this bug ???

    Mail : jperriard@floor.ch
    SkyPe : floor004

    Thanks, Julien

  104. Andy Says:

    Very Handy!

    I would love to see a few extra features added…

    If anyone feels up to the follow changes let me know, there might be some cash in it for you!

    1) Drag from a “Master List” on the left to a “Playlist” on the right. This would require a copy or clone feature (as so many have requested so far). Items dragged from the left would be added to the list on the right (but would remain in the master list on the left when the submit button is hit. So only the list on the right would be updated). It would also be nice to lock the items in the master list so they can be dragged out of the list but not dragged anywhere else within their own list (however the ability to sort the order of the items in the master list would be nice: by name, id, date etc). The list on the right would be sortable however.

    2) Garbage Can - Somewhere to drag items from the Playlist (list on the right) so they are deleted.

    3) Clickable Links - Each item would be clickable as well dragable. Ideally the links would come from a column in the database.

    4) Add New Item - The ability to type in a text field and hit submit and add the item into the list on the right. This would be perfect for adding Titles for categories for example)

    5) Change List on Right - The ability to select from a drop down (or something else) different lists on the right. Each list could be a different table in the database or something?

    What I am looking for may be somewhat like the mods Sebastian Moser (see Post #2) has made?

    If anyone feels up to the challenge of any or all of these mods please let me know! If you have any questions just email me! I am comfortable with PHP and MYSQL but my javascript/ajax skills are limited.

    Thanks, Andy ( junkedout@gmail.com )

  105. Chad Sanders Says:

    Here’s some code for the window autoscroll.. now where is it supposed to go? I’ve tried numerous places inside of the script without much success.

    if (y > (window.innerHeight + window.pageYOffset - 10)) {
    window.scrollBy(0,10);
    }
    if (y

  106. Emile Schenk Says:

    I added support for scrollable DIV, see here:
    http://austroweb.at/software/javascript_drag_drop/javascript_drag_drop.htm

  107. luenib Says:

    Tom,

    The link you gave Dipesh (http://kiwi-interactive.com/experiments/inlineEdits/drag.html) regarding the tables and rows swaping no longer exists. Do you have any other reference?

    Thanks
    Luenib

  108. luenib Says:

    My point is: what should I do to modify the code in dragdrop.js so I can work with tables and rows instead of ul’s and li’s?

    Thanks again
    Luenib

  109. seba Says:

    Hey,
    I’m making a online file managing system where I use this, but is anyone able to get it so, that if they move one element from one list to an other, it just updates that element.
    So it just calls like a page: update.php?elementid=Seven&list=center
    and then I can just update that one?

    I can pay for this if this can be done.
    mail me @:
    seba.kerckhof@gmail.com

    I have also made something that dynamicly makes new lists (in ajax) but, it also has to add something in the tags that initialate the list, but I can’t get it to work, if anybody can do this (I can pay for it) also mail me.

  110. Ton van de langkruis Says:

    Hi Emile,

    Thanks for trying to add the scolling. I tried it out, but actually it did not work in (in i.e.6.0). It did work on your page if you want to move an item from one column to the other, but not if you work with only one column.
    Funny thing is that if you want to take an item down within the same column, and you reach the end of the window, intuitively you use the scroll wheel of the mouse, and the window moves down. But when you then continue dragging the item down, the pointer will move down, taking distance from the item, but the item won’t move further.
    How to solve this?

  111. Jan Boeijink Says:

    Page autoscroll, asked for by Chad Saunders (#105): see my example, which is working in Safari and Firefox. Please test in IE 6.
    By the way: 10px is way too fast! I took only 2px :)

  112. Jan Boeijink Says:

    Surprise: my example is not working in IE 6.
    I assumed Tom’s script was based on Toolman’s (Tim Taylor) original code, which includes some lines for scroll support. Maybe Tom’s script was based on an earlier version, or maybe he left out some things, I don’t know…
    Both pages (Tim’s and Tom’s) were not updated for a long time, apparently they don’t have time or interest anymore. We could use a combination of both versions.

  113. Chris Schneider Says:

    There is a bug in the script. When you drag out of any of the containers, and let the item bounce back to the end of the original one, it doesn’t clean up after itself. It leaves ul elements laying around. Every time you do that it creates a new one. Typically it doesn’t matter, but due to a quirk in my CSS, they showed up. The fix is to add the code:

    var tmpContainer = this.parentNode;
    tmpContainer.parentNode.removeChild(tmpContainer);

    Into onDragEnd, right after the while(container!=null) block. (not inside that, after). That cleans up the orphan elements.

    You can see these elements if you have firefox and the firebug extension. Just inspect the DOM, and close/open the body tag to refresh it.

    Hope that helps somebody.

  114. Rebecca Says:

    This tool is great! I love using it! Simple, elegant, effective…

    I think the bounceback feature may be causing problems with updating the database - I can’t get the items to be updated properly in the second example when I drag them out of the area.

    Also, I’d like to use a trash can feature in my projects… is there a way to get the code for that?

    Thanks!

  115. Rebecca Says:

    Maybe I should clarify -

    When I drag an item out of one of the lists and it bounces back, it appears to be at the bottom of the list. In the database, however, the item retains its previous position (”order” field).

    Thanks!

  116. Wes Says:

    I was able to get the cloning to work so that you can drag from one list and the item does not get removed, but instead duplicates into the second list. I think it works as intended.

    http://71.79.237.113/hosting/dragdrop.html

  117. Will Says:

    So, I know I’m kind of an idiot, but I’m needing some help with this script :(.

    I’ve got it pulling information from my db into one list. I’ve changed it so that there’s not an order table in the database, but just added an “order” field onto the table I’m pulling from.

    I’m setting up a newsletter system so the database already contains “article_id” and “issue_id” columns, along with the “order” column I added.

    I would like to use the ajax method, so I need to know what I don’t need to keep ahold of (as far as code) and then how to go about altering the sql queries :(.

    I know I’m asking a lot, but like I said, I’m an idiot. I’ve been working on this all day and I’m just now getting it to pull my records correctly.

    If anyone could help me out, that’d be great. If you want to see an example or whatever, here’s the actual page I’m working on:

    http://www.fhsu.edu/willp/ajax/dd/dd.php

    Thanks for all your help,
    Will

  118. Peter Rehm Says:

    Hi,

    i tried to improve the code, to make it a bit more oop :)

    http://peter-rehm.de/2006/06/20/multi-list-drag-drop-sajax/

    Sorry the Page is in german, but anyway you can download the Files there and have a look. Also an Example Page is given, but you need to watch the code.

    It is working in FF, Safari, IE6, i couldnt find any errors…

  119. EXE.trim.ALL Says:

    Hello! How I can combine functionality of multi list dnd, dnd shopping cart and Tim Taylor’s lists dnd. I want to use it in my CMS. You can see example of my work with this scripts ported to xajax there: http://execms.jino-net.ru/ ; login: admin, pass: 1; http://execms.jino-net.ru/?act=admin&mname=exe_menus&a=menu_edit&id=2
    Thanks to all!

  120. EXE.trim.ALL Says:

    After rest I observed sortable function in this script and made menu editor. But I also need to know hot to create handlers, I tried but failed. http://execms.jino-net.ru/?act=admin&mname=exe_menus&a=menu_edit&id=2
    login: admin, pass: 939

  121. Shuja Shabandri Says:

    Great Work Tom,
    you saved my job :)

    To make items draggable by handle

    Title
    other content

    in dragdrop.js

    change
    item.setDragHandle(item);
    to
    item.setDragHandle(item.childNodes[0]);

    I couldnt figure out without making this change.

    Cheers & Thanks
    Shuja

  122. simon Says:

    Hi - I wandered if anyone new how to get around a problem I’ve encountered?

    I have two lists, the first list is pretty long, and around 50-60 items, and the second list start empty.

    When I scroll down the page to the bottom of the first list and attempt to drag an item from the bottom to the top of the second list there is a necessity to scroll the page back up, but this is where the problem occurs. When I scroll up - whilst dragging the item - the item stays in it’s original position prior to scrolling, so in effect it gets left behind and I can’t add the item to the second list.

    I hope you know what I’m getting at?

  123. Adam Says:

    Hi!

    I tried to make all the functionality without a database and php, using only cookies and javascript. After rebulding the boxes with DOM, the drag and drop feature doesn’t work.

    http://kampany.vnubp.hu/dnd/dd.htm

    If anyone could help me out, that’d be great.

  124. Adam Says:

    It works now

  125. cameron Says:

    hello,
    this is just awesome. I’ve been looking at similar solutions, and keep hitting the same wall with them. But yours looks most promising for what i need, but i’m still a tad unsure. I want to be able to submit the order to a separate (or the same) database for a poll. where 1 person could rank things 1,2, 3, 4, and 5. then another would rank things 3,2,1,5,4… etc…

    is this at all possible?

  126. Inderpal Singh Says:

    Hi Tom,

    I have tried your code and it’s a great piece of work. I was trying to customize it according to my specifications. I would appreciate if you help me to make it work.

    1. Is it possible if I don’t want to drag any particular element from a list?
    2. I dragged an item from first list to second list. Now what I want is when I dragged that item outside of any container, instead of returning to second list it should return to the first list.

    I am working on above two problems. I would appreciate if somebody helps me in this regard.

    Best Regards,
    Inderpal Singh

  127. David Says:

    Shuja,

    I’m using the original code provided by the author and cannot find the following line:

    item.setDragHandle(item);

    How does one get the hot spot / handle working?

    It would be a great help

    David

  128. Inderpal Singh Says:

    Hi All,

    The script is working great. I was working on to make the copy/clone of item while dragging from one of the list.

    Wes, I think you have achived the same. The URL given by you is also not accessible. I would appreciate if you give me any pointers/directions to make it work.

    Thanks in advance!!

    Best Regards,
    Inderpal Singh

  129. Paul Caligari Says:

    Doh… some of the links to the modifications made to this script have vanished. I really could do with a valid link to a version of this script that…

    1] does the clone drag and drop between lists
    2] Really nice if the lists could be nested and the clone contained whatever is nested inside the original element
    3] Included the edit functionality so that cloned elements can be renamed
    4] Allowed the lists to be collapsable (cross browser)

    Basically what I’m trying to do is have a fixed, nested list on the left and allow the user to drag cloned fron this master list into an empty list on the right. They should then be able to rename the list elements by clicking on them.

    If any one has any live links to version of this script that accomplish at least the cloning it would be appreciated.

  130. Maik Lehmann Says:

    Great work! - Now all works fine in my new configurator…

    Thanks to all!
    Maik

  131. sriram Says:

    >>> I was able to get the cloning to work so that you can drag from one list and the item does not get removed, but instead duplicates into the second list. I think it works as intended.

    http://71.79.237.113/hosting/dragdrop.html

  132. sriram Says:

    Hi Wes, could you please post the example. The link is not working.

  133. Ulrich Says:

    If you go to http://71.79.237.113
    it lists an email - it doesn’t say Wes though.
    maybe email him and post the answer.

  134. Inderpal Singh Says:

    Hi Sriram,

    I think URL is not accessible. Could you please post it again?

    Best Regards,
    Inderpal Singh

  135. omar alhakeem Says:

    Hi guys I need your help! I want to build an request form on the intranet with voucher generator which has full control on all in & out data inquiries and is connected to a database built in a way that data can be extracted and retrieved easily.

    I work in the archive unit and we have our vault where I from prepare requests to other personnel’s.

    Requires:

    A request form full with the most form fields, text , drop list , text field , radio, check box, …etc
    On submit the form will be sent as Email to the archive unit with all the required information’s.
    The archive clerk will open that request and prepare it for pick up.
    Once every thing is ready to go, the archive clerk will need to generate a voucher for signature by the requester, and simultaneously by clicking on print voucher it will extract data from the data base.
    On the other hand, when materials are back from users, there will be a receipt voucher waiting for them, and simultaneously by clicking on print voucher it will retrieve data back to the data base.

    IS THAT EASY TO BUILD? AND HOW!

    NOTE:

    The database at the beginning will be build manually as the request will be received by Email.

  136. unknown Says:

    http://71.79.237.113/hosting/dragdrop_new.html

  137. David Says:

    Anyone have a solution for the handle part of this yet? This seems to me to be a very important option to have.

    David

  138. Rebecca Says:

    Love it - still looking at a bug…

    The items don’t update properly in the database if you use the bounceback feature. Anyone have a fix?

    Also - I’m looking to implement a “garbage disposal”. I want to be able to delete items from the list (possibly by just dragging them out of the list area). Does anyone have the OLD code (that incudes this functionality)?

    Thanks!

  139. Adam Says:

    Hi All,

    So here is the last and working url.

    http://www.hirstand.hu

    You can reorder the boxes and all stored in cookies.

  140. Francisco Ferreira Says:

    Hi all,

    this is a great script!!! Congratulations!

    I made a workaround to get clonning to work to, here it is:

    1) Save the fixed UL content:

    var list = document.getElementById(”source”);
    var savedValues = list.innerHTML;

    2)Everytime the users drop it reloads the saved content:
    function onDrop2() {
    var list = document.getElementById(”source”);
    list.innerHTML = savedValues;
    window.onload();
    var data = DragDrop.serData(’g1′);
    alert(data);
    }
    ..
    ..
    window.onload = function() {

    var list = document.getElementById(”source”);
    DragDrop.makeListContainer( list, ‘g1′ );
    list.onDragOver = function() { this.style[”background”] = “#EEF”; };
    list.onDragOut = function() {this.style[”background”] = “none”; };
    list.onDragDrop = function() {onDrop2(); };

    .
    .
    .

  141. axis Says:

    Hello,

    is there a version to save positions with cookies ?

    Thanks a lot

  142. aris Says:

    love the script. i was able to make it work with JSMX and all, but this version of the script has an awful time dealing with 2-dimensional lists. please… if anyone has corrected the script to function correctly in 2-dimensions, let me know. it’s unfortunate to be limited to an up-down only single-file list that stretches beyond the browser and doesn’t scroll properly. i even looked at yahoo’s yui library for ideas to help the drag and drop, but that’s all a big mess.

  143. Chris Says:

    I have to lists so user can drap between, to start with on list is empty and i would like to have the empty to have a min height so it is easier to drag o the empry list, I don’t know if this can be done, if it can be you some help of how to set this up

  144. Peter Rehm Says:

    I updated the class for the AJAX lists. Now its more flexible. E.g. you can easily ass more than 3 sections for managing elements. only give the name of the columns while calling the class. Some more small things added to make the code more pretty and to improve the handling.

    Maybe its useful…

    Link to the blog entry (german) http://peter-rehm.de/2006/09/01/multi-list-drag-drop-part-2/

    Link to the Demopage + Download (english): http://peter-rehm.de/downloads/sajax/demo.php

    Have fun!

  145. BlackMisery Says:

    Hi All,
    I’m developing a site in PHP/MySql that requires Ajax for this feature
    : The user read an article and if ever he likes it he can drag it and
    drop it into his “basket”. Then when he’ll consult its account he’ll
    found that article. I think it’s easy to do but I’m a beginner and I
    didn’t found any help. Please help.
    Thanks.

  146. matt Says:

    how could i make the list items divs? insted of li tags.

  147. Burke Says:

    To start, I have extensive background in php and html, but very little in javascript. Here are a few ideas for you javascript gurus out there:

    This is by far the best drap and drop. It is much better than script.aculo.us. I have done tons and tons of looking, and this is the best.

    The only real bug (IE and Firefox) is that whenever you drag a to another box and enter the box slowly, there is a weird twitch. There is also a twitch at the the bottom of lists more frequently. Lastly, an empty container in Firefox is really small.

    Animations would make this script really sweet. Maybe have an animation for the bounce-back and possibly the shuffling in the containers. Maybe use script.aculo.us?

    Furthermore, I have need to constrain one or two elements to a list but allow other elements to be added and removed from the same list. Also, the constrained elements would have to be sortable in the list that they’re contrained to. I was thinking something like a vertical constraint or something? Let me know if you have any ideas.

    Thanks!

  148. Inderpal Singh Says:

    Hi Francisco,

    You have done a great job. Could you please post your complete code for cloning?

    Best Regards,
    Inderpal Singh

  149. Fernando Dichiera Says:

    I’am Argentinian, sorry for my bad english!!! first, your examples is wonderfull !!! second i have a question, in http://www.fad.com.ar/drag.html have an implementation de your example with a error, one list is in a table, second list is in a layer, draging between list 2 and 1 the first item is ok, but drag the last items for example the item 35 on list 1 one stranger error it happens
    you have idea that can happen?
    thanks in advance

    Fernando Dichiera
    from Argentina the south America

  150. Martin Says:

    Hi Tom

    Like your script, but is it possible to use div tags instead of list?
    I also would like to use the script with two table in a join sql.

    Is this posible?

  151. Viki Says:

    Hi,
    please help me out in altering above script to leave a copy of it in source div like shopping cart.

    Thanks In Advance..

  152. Burke Says:

    This is an incredible script, truly the best I have found. I was wondering if anyone had experimented with limiting the motion of certain tags. For example, I want two tags to stay in one list, but I want them to be able to be sortable with the rest of that list. I want to contrain these two tags to one list and keep them from even exiting the list. Let me know if you have any ideas.

  153. Craig Says:

    Sam (Post #59) was close with the handler idea but there were a few errors.

    1) Put the DragAllowed = false; line BEFORE the line: function confirm(z)

    2) You also need to put DragAllowed = false; just before the line return false; in the onMouseDown : function(event) { of drag.js

    Also, you can’t have the “AllowDrag=true” in the mousedown event of the LI object, it has to be lements inside that.

    Seems to be a lot of people asking for this. Hope it helps.

  154. Murtaza Says:

    It is good but some one can help me in such script in which i can drag and drop a compplete row populated with DB contents and also one complete column and also a single item.

  155. rpestana Says:

    How i add more elements, after load the list.

    makeListContainer : function(list, group) {
    if (this.firstContainer == null) {
    this.firstContainer = this.lastContainer = list;
    list.previousContainer = null;
    list.nextContainer = null;
    } else {
    list.previousContainer = this.lastContainer;
    list.nextContainer = null;
    this.lastContainer.nextContainer = list;
    this.lastContainer = list;
    }

    list.onDragOver = new Function();
    list.onDragOut = new Function();
    list.onDragDrop = new Function();
    list.group = group;

    var items = list.getElementsByTagName( “li” );

    for (var i = 0; i

  156. fnapz Says:

    To add a handle :

    Edit dragdrop.js
    line 83 :
    makeItemDragable : function(item) {
    Drag.makeDraggable(item);
    item.setDragThreshold(5);
    item.setDragHandle(item.childNodes[1]);// ADD THIS

    // tracks if the item is currently outside all containers
    item.isOutside = false;

    item.onDragStart = DragDrop.onDragStart;
    item.onDrag = DragDrop.onDrag;
    item.onDragEnd = DragDrop.onDragEnd;
    },

  157. Karl Beyer Says:

    I have implemented the cloning basically off Francisco’s idea. As the item leaves its original container, we clone it, and append it to the parentNode. On DragEnd, if we are back in our original container, we simply destroy the clone object which was originally created (the user may have wanted to reposition within the same list).

    A welcome side effect of this if you drag an item outside all containers, and let go off the mouse, the item is sitting right where the item originally was. At that point, my modification to the script simply throws the original node away and leaves the clone in the original container.

    The only modifications are to the DragDrop.js file, but I have included the other two script files (coordinate.js and drag.js )for completeness sake.

    One further thing, I have left it up to the developer to tweak to their needs (there is nothing preventing the user to clone between two lists for example, you can stop that behavior by simply not attaching the dragLeave event to items in the list you wish not to be cloned).

    Here’s the links:
    http://www.beyerphotography.com/drag.zip
    (or if you can’t decompress WinZip files, just swap the contents of the dragdrop.js file included in this blogs downloads with the text from the below link and save the file.) http://www.beyerphotography.com/dragdrop.txt

  158. Nor Says:

    Drag & drop is very util.
    I have same problem that item 29.

    I use overflow: scroll and height in ul boxy (css) but I dont drag & drop item down.

    I dont know how solution. Can you help me please??

    Thank for your atention.
    Regards.

  159. Ulrich Says:

    Hi, anyone with working cloning code?? Please!!!

    TIA

  160. 100procent Says:

    Ive added one thing i think its quite useful,
    If for example you want to be able to move elements form list X to list Z but block from Z to X.

    example:


    DragDrop.makeListContainer( list, 'g1', true );
    // true - list.allowdragto = true

    To Change:

    list.group = group; //under this add :
    list.allowdragto = allow;

    Then look for this “container.group == parent_group”
    and change it everywhere to
    “container.group == parent_group && container.allowdragto == true”

  161. Matt Says:

    Can anyone get this working with the mysqli extension, rather than mysql? For the life of me I just can’t do it. It loads fine but just can’t parse the data. It doesn’t seem to handle the update_db function.

  162. Mathachew Says:

    I haven’t read through any of the previous 148 posts, so forgive me if this has already been discussed.

    http://216.253.95.34:20001/list.gif

    In CMS Made Simple, there is a feature to sort the order of your navigation, with lists inside of lists, all sortable. While being able to move one list item to a completely different list would be nice, the implementation that is set in CMS Made Simple is sufficient to get the job done. However, going through their code was a headache. I tried to accomplish this with your modified version, without success.

    Basically, the first listed items are sortable between each other. The second tier items are sortable between each other, and so on and so forth with a third tier. Would you be able to update the script to allow for this? Currently, any additional tier lists, when clicked on, are behaving as if you clicked on the parent list.

    Make sense?

  163. Amit Says:

    Hi,

    Can any one tell me how in existiing drag & drop script auto scrolling of browser window can be done when drag element reaches top or bottom of screen window.

    THX in advance for any help on this auto scroll thing.

    Cheers !!!

  164. Tony M Says:

    In reply to Post #87 (Jason),

    I found a simple solution to this problem. You can solve the Firefox bug by adding an event to the INPUT tag…

    {input onmousedown=”this.focus()” ……. }

    I have v2.0 installed, so I wasn’t able to test it on 1.5x, but I expereinced the same problem you described so I assume this might fix the issue on any recent version…

    Sorry it’s almost a year later…

  165. sanks Says:

    Here is a simple web page, that allows the user to select any of the cells in the bottommost row and place the cursor on any on the top rows. the selected charatcer appears in the designated cell. But I want to make it user-friendly, drag and drop feel.

    %@ Language=VBScript %>

    function fn_place(name)
    {
    //alert(name);
    document.getElementById (name).value=document.getElementById (”hidden_text”).value
    //alert(document.getElementById (”hidden_text”).value);
    document.getElementById(name).style.color = “red”
    }
    function fn_set(val)
    {
    document.getElementById (”hidden_text”).value=document.getElementById (val).value
    //var tmp=document.getElementById (”hidden_text”).value
    //if(document.getElementById (tmp).value==”")
    // document.getElementById (tmp).value=val
    //else
    //alert(”Cannot be replaced….choose another cell”);
    }
    function fn_score()
    {
    var tmp=”";
    var word = new Array();
    var idx=0;
    for(i=1;i

    col” size=”2″ onclick=”fn_place(’rowcol’)” readonly>

     

    ” value=”" size=”2″ onclick=”fn_set(’btn’)” readonly>

     

    “” then

    words=Request.Form (”hidden_words”)

    ‘Response.Write words

    arr_words=split(words,”;”)
    mark=0

    for i=lbound(arr_words) to ubound(arr_words)

    Set fs=Server.CreateObject(”Scripting.FileSystemObject”)
    Set f=fs.OpenTextFile(Server.MapPath(”dict_words.txt”), 1)

    do while f.AtEndOfStream = false

    ‘if lcase(trim(arr_words(i)))=lcase(trim(f.ReadLine)) then
    if strcomp(lcase(trim(arr_words(i))),lcase(trim(f.ReadLine)),1)=0 then
    ‘Response.Write(arr_words(i))
    mark=(mark*1)+(1*1)
    %>

    “)
    end if

    loop

    f.Close
    Set f=Nothing
    Set fs=Nothing

    next

    Response.Write (”Score = “&mark )
    %>

  166. Thomas Says:

    I’m trying to have a nested list, where I can drag any li to another place in the list. I have found some scripts that can partially do this, like a widget for the YAHOO Library, but the problem is, as soon you drag the last item from a sublist you cannot add any child elements again. I had the idea to add a dummy element when this happens and remove it as soon a real item gets dropped on it. But making the dynamically added dummy element a droppable is a pain in the a**. Beside of that I’m not a huge fan of the YAHOO Libraries. So if any of you have a better and/or easier way to do what I want to achieve, i would be very grateful.

    Example:

    Logos

    RGB
    Grayscale
    Pantone

    Fonts
    Stylesheets

    RGB have to be moveable to the first level like “Logos”; “Fonts” and “Stylesheets” but also as a child of “Fonts” or “Stylesheets” or even as a dhild of “Grayscale” or “Pantone”.

  167. Thomas Says:

    “RGB”, “Grayscale” and “Pantone” were meant to be child elements of “Logos”…

  168. Morten Says:

    Can i load a page into the boxes i move around?

  169. Martin Says:

    I had a problem where I had a small width left hand column and a larger width right hand column and found that because it checks the whole div has done a dragout from the source list you couldn’t move into the left hand destination list.

    The solution I found was the following:

    In dragdrop.js within the onDrag function

    Change:
    if ((nwOffset.inside( container.northwest, container.southeast ) || seOffset.inside( container.northwest, container.southeast )) && container.group == parent_group) {
    To:
    if ((nwOffset.inside( container.northwest, container.southeast )) && container.group == parent_group) {

    And:
    } else if (!(nwOffset.inside( this.parentNode.northwest, this.parentNode.southeast ) ||
    seOffset.inside( this.parentNode.northwest, this.parentNode.southeast ))) {

    To:
    } else if (!(nwOffset.inside( this.parentNode.northwest, this.parentNode.southeast ))) {

    This (I believe) means it’s just checking the top-right corner for position rather than the whole div.

    Hope this helps someone - well done Tom :)

  170. Null Says:

    Hi,

    Is this possible and how to do it:

    I want to add an icon/gif in each draggable object. When pressing this icon, the text (One, two etc) in that object will be editable. So then I can change Seven to Treehouse or something. After hitting enter, or clicking the icon again will make the text un-editable again.

    When pressing the submit button will update the order AND the text in the db….

    This way I can edit the text easily!

  171. add Says:

    very nice code here, it works weel, thanks!

  172. med Says:

    hello
    can you help me please ?
    actually, i’am using your drag and drop source into my web site but i need it to work differently than the way it used to i mean i would like that the element will be dropped once the mouse pointer touch the zone on witch the element had to be dropped.

  173. Andrew Says:

    For those of you who are having problems with an empty list being too small to add too, here is a CSS fix that works cross browser to designate a minimum height. Change the px to whatever height you choose.

    If the elements are larger than the minimum it will automatically stretch.

    ul {
    min-height:160px;
    height:auto !important;
    height:160px;
    }

  174. Andrew Says:

    In post #149 a user seems to have solved the problem with overflow:auto and overflow:scroll in IE. This is his link.

    http://www.fad.com.ar/drag.html

    Unfortunately, I don’t have any clue how he managed to do it. Does anyone have any instructions on how to pull off a modification to the script that will complete this feature?

  175. Wladimir Says:

    Hi,

    I dont found the scripts of the your first post.

  176. Seanie Ryan Says:

    in the update_db function, change the foreach section to the following. In a long list, then instead of an sql query for each item to update, you end up with just 2 sql querys. Massive speed increase. I brought a page from over a minute down to 2 secs.

    foreach($data_array AS $set => $items)
    {
    $i = 0;
    foreach($items AS $item)
    {
    $item = mysql_escape_string($item);
    $set = mysql_escape_string($set);
    $casequery1 .= ” WHEN item = ‘$item’ THEN $i “;
    $casequery2 .= ” WHEN item = ‘$item’ THEN $set “;
    $i ++;
    }
    mysql_query(”UPDATE layout SET order = CASE $casequery1 END $col_check”);
    mysql_query(”UPDATE layout SET set = CASE $casequery2 END $col_check”);
    }

  177. Eduard van den Bongard Says:

    Hi there,

    I am interested in having a specialized version of your multilist. Please contact me.

    Best regards,
    Eduard

  178. aaron Says:

    Hey Tom, Very cool script. How would I add an add and delete option to it where I could enter a name in a text box, hit a button and it would be added? Also how could I just drag an item from the list and it would be deleted? Thanks, Aaron

  179. Roj Says:

    Great Script.

    I am trying to make nested draggable lists. does anybody know how to do it.

    Thank you

  180. Vincenzo Says:

    Hi to all,
    it’s a great script. But i have a problem:

    I don’t have a list but a “table” with 5 elements per row.

    If i want drag element5 between 2 and 3 it’s not work.

    I have found a script to do it but i can’t drag elements between two list.

    Have you a patch? i am a php programmer, not js!

    thanx a lot!

  181. BJ Says:

    Cool script.

    I know zip about Ajax and PHP so i downloaded the example and tried to set it up on my site to see if i could get it to work.

    It doesnt =/

    I’ve defiened db, user and pw but nothing happens.

    Do i have to install anything to get it to work? Im such a nuub a MySQL and PHP.

  182. achimappel Says:

    Hi,

    greatful!!
    I use the li-Containers and it work fine, but I’ve one problem:
    If i use container in Tag, the frame-line doesn’t go around the div object. Is there any Solution for it?

    Thanks
    achim appel

  183. aaron Says:

    Hi Tom, Awesome stuff! In your sajax example source code I’ve modified the echo line below and added some CSS. But when I drag the item from sajax2 to sajax1, and then refresh the page, the values in the text box are still in the sajax2 list even though the item itself is gone. How do I get rid of the values in the text box as well when dragging from one list to the other? Thanks, Aaron

    $rw[item]”;

    }
    ?>

    The style

    input {
    position:absolute;
    top:0;
    right:0;
    height:18;
    width:30px;
    }

  184. aaron Says:

    Whoops the php didn’t come out, I’ll try again here.

    $rw[item]”;

    }
    ?>

  185. Jay Says:

    Thanks for this. Very useful stuff!

  186. Jay Says:

    re: #76 - Thank you Marcus! This has made my page a whole lot faster (only updating the item that needs to be updated, and only do an update if the item actually moved).

  187. John H Says:

    The only thing missing from your excellent demo is to add a handle to each container and make the groups sorted.

  188. John H Says:

    So my question is: can this library reproduce the behavior found here:

    http://www.gregphoto.net/sortable/advanced/

    That is, sortable items within sortable groups containers WITH handles? I suspect this example could be modified to do so. I’m willing to take a stab at it, but I thought it would be worth asking if someone has already tried it.

  189. Christian A. Coryell Says:

    Really like your PHP adapation of the drag and drop shopping cart. I have a project running currently. If you have any time for some side projects, please contact me as I would be interested in paying you to do some contract work.

    Best,

    Christian A. Coryell
    President/CEO Atwood Marketing Group

  190. Jeremy Says:

    Lizardware CMS as of beta 3 now uses this for its menu managment

    Also as of the next version your gmail username checker is also going to be used

  191. Dolobene Says:

    …are the scripts off?

  192. Pranav Rana Says:

    Nice work

  193. Mike Says:

    Amazing script, but I am having issues with scrolling. has anyone found a solution for it yet. When I scroll down and then drag, as soon as the LI leaves the container it repositions itself on the screen.

  194. Nor Says:

    Hi

    I need select