473,394 Members | 1,828 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

list drag and drop sortable

Somewhere I've seen a list that is drag and drop sortable, where you
can "grab" a list item and move it up or down the list.

Can someone summarize how this is done. I really don't want to hack
my way through something like scriptaculous.

Jeff
Aug 16 '08 #1
4 2614
On Aug 16, 4:35*pm, Jeff <jeff@spam_me_not.comwrote:
* *Somewhere I've seen a list that is drag and drop sortable, where you
can "grab" a list item and move it up or down the list.

* *Can someone summarize how this is done. I really don't want to hack
my way through something like scriptaculous.
1) mousedown event
determine the target element in list
record mouse position
2) mousemove event
determine relative position of mouse to starting position on
mousedown
move the target element visually (position:relative helps)
3) mouseup event
move the element in the DOM to its new position in the list

Peter
Aug 17 '08 #2
Peter Michaux wrote:
On Aug 16, 4:35 pm, Jeff <jeff@spam_me_not.comwrote:
> Somewhere I've seen a list that is drag and drop sortable, where you
can "grab" a list item and move it up or down the list.

Can someone summarize how this is done. I really don't want to hack
my way through something like scriptaculous.

1) mousedown event
determine the target element in list
record mouse position
2) mousemove event
determine relative position of mouse to starting position on
mousedown
move the target element visually (position:relative helps)
I'm having trouble here:

simplified example

document.onmousedown=mouseDown;

function mouseDown(e){
e = e || window.event;
target=e.target || e.srcElement;

if(target.nodeName == 'LI'){
target.position = 'relative';
target.style.top = '400px';
// li does not move
}

Yet, this "works":

<li style="position: relative;top: 400px">this is offset</li>

What have I missed? Doctype is strict.

Jeff
3) mouseup event
move the element in the DOM to its new position in the list
>
Peter
Aug 17 '08 #3
Jeff wrote:
Peter Michaux wrote:
>On Aug 16, 4:35 pm, Jeff <jeff@spam_me_not.comwrote:
>> Somewhere I've seen a list that is drag and drop sortable, where you
can "grab" a list item and move it up or down the list.

Can someone summarize how this is done. I really don't want to hack
my way through something like scriptaculous.

1) mousedown event
determine the target element in list
record mouse position
2) mousemove event
determine relative position of mouse to starting position on
mousedown
move the target element visually (position:relative helps)

I'm having trouble here:

simplified example

document.onmousedown=mouseDown;

function mouseDown(e){
e = e || window.event;
target=e.target || e.srcElement;

if(target.nodeName == 'LI'){
target.position = 'relative';
target.style.top = '400px';
// li does not move
}

Yet, this "works":

<li style="position: relative;top: 400px">this is offset</li>

What have I missed? Doctype is strict.
I've solved that by defining the position: relative in the CSS first.

How do I move a node from one place to another?

I'm pretty close as I've written an array of siblings with their y
positions, now I just need to move the node.

Jeff
>
Jeff
>3) mouseup event
move the element in the DOM to its new position in the list
>>
Peter
Aug 17 '08 #4
On Aug 17, 10:53*am, Jeff <jeff@spam_me_not.comwrote:
Jeff wrote:
Peter Michaux wrote:
On Aug 16, 4:35 pm, Jeff <jeff@spam_me_not.comwrote:
* *Somewhere I've seen a list that is drag and drop sortable, where you
can "grab" a list item and move it up or down the list.
>* *Can someone summarize how this is done. I really don't want tohack
my way through something like scriptaculous.
1) mousedown event
* * *determine the target element in list
* * *record mouse position
2) mousemove event
* * *determine relative position of mouse to starting position on
mousedown
* * *move the target element visually (position:relative helps)
I'm having trouble here:
simplified example
document.onmousedown=mouseDown;
function mouseDown(e){
* * e = e || window.event;
* * target=e.target || e.srcElement;
if(target.nodeName == 'LI'){
* * target.position = 'relative';
* * target.style.top = '400px';
// li does not move
}
Yet, this "works":
<li style="position: relative;top: 400px">this is offset</li>
What have I missed? Doctype is strict.

* *I've solved that by defining the position: relative in the CSS first.

* *How do I move a node from one place to another?
http://developer.mozilla.org/en/docs...t.insertBefore

Note with insertBefore you can insert at the end of the list as
discussed on that page using null.

Peter
Aug 17 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Dwayne Gaddy | last post by:
Hey all, I have a windows form with a list boxes. I have data bound the list boxes with data from my sql database. I want to use drag and drop to allow users to choose different options from the...
0
by: Lauren Quantrell | last post by:
I'm trying to drop a file from Windows Explorer (or desktop, etc.) onto a field in Access2K and capture the full file path. I found an posting below that says this is possible but I cannot...
6
by: jojobar | last post by:
Hello, I look at the asp.net 2.0 web parts tutorial on the asp.net web site. I tried to run it under firefox browser but it did not run. If I want to use this feature in a commercial product...
3
by: JL | last post by:
I have found may examples for dragging and dropping between list boxes but I need to do it within one. Can some one point me to a tutorial or example. Prefer VB but can use C# too. TIA, John
0
by: jawilson | last post by:
Hello, I am trying to use drag-n-drop for a listview control in my program. I created a new listview control class (just call it MyListView) that inherits from ListView, and creates a few new...
5
by: empiresolutions | last post by:
Hello Fellow Developers, I am using the awesome drag and drop script found at http://script.aculo.us/. I have also added a modification that interacts to a db for reordering upon release of a...
1
by: libsfan01 | last post by:
hi im using drag and drop on my site, my problem is if i drop the content on a part of the page other than a container, that content disappears. is there someway to prevent this? here is my...
5
by: Romulo NF | last post by:
Greetings, I´m back here to show the new version of the drag & drop table columns (original script ). I´ve found some issues with the old script, specially when trying to use 2 tables with...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.