トップへ(mam-mam.net/)

Edit Tables with Drag & Drop: Move, Copy, and Delete Rows in JavaScript

Japanese

A Copy‑and‑Paste Drag & Drop Table for Moving Rows

With mamdragdrop.js, all you need to do is add class="mam_dragdrop" to the table element where you want to enable drag‑and‑drop functionality.
<table class="mam_dragdrop">
Download mamdragdrop.js (5KB)
At the top of mamdragdrop.js, you can configure this.canCtrlDropCopy and this.canAltClickDelete (true or false) to enable or disable row copying with Ctrl+Drop and row deletion with Alt+Click.

// Settings
this.canCtrlDropCopy = true;   // Enable row copy with Ctrl + Drop
this.canAltClickDelete = true; // Enable row delete with Alt + Click

■How to Use

■Usage Example

You can drag and drop the icon on each row to move rows within the table.
Holding the CTRL key while dragging will copy the row instead of moving it.
Holding the ALT key and clicking the icon will delete the row.
(You cannot delete all rows. The last remaining row cannot be removed.)

Column Title1 Column Title2
Cell1-1 Cell1-2
Cell2-1 Cell2-2
Cell3-1 Cell3-2
Cell4-1 Cell4-2