A quanto pare la domanda descrive mal problema del PO, ma questa domanda è il risultato della ricerca in alto per il trascinamento per riordinare le righe della tabella, quindi w cappello risponderò.Non ero interessato a portare in jQuery UI per una cosa così semplice, ecco un unica soluzione jQuery:
<style>
.grab { cursor: grab; }
.grabbed { box-shadow: 0 0 13px #000; }
.grabCursor, .grabCursor * { cursor: grabbing !important; }
</style>
<table>
<tr><th>...</th></tr>
<tr><td class="grab">☰</td><td>...</td></tr>
</table>
<script>
$(".grab").mousedown(function (e) {
var tr = $(e.target).closest("TR"), si = tr.index(), sy = e.pageY, b = $(document.body), drag;
if (si == 0) return;
b.addClass("grabCursor").css("userSelect", "none");
tr.addClass("grabbed");
function move (e) {
if (!drag && Math.abs(e.pageY - sy) < 10) return;
drag = true;
tr.siblings().each(function() {
var s = $(this), i = s.index(), y = s.offset().top;
if (i > 0 && e.pageY >= y && e.pageY < y + s.outerHeight()) {
if (i < tr.index())
s.insertAfter(tr);
else
s.insertBefore(tr);
return false;
}
});
}
function up (e) {
if (drag && si != tr.index()) {
drag = false;
alert("moved!");
}
$(document).unbind("mousemove", move).unbind("mouseup", up);
b.removeClass("grabCursor").css("userSelect", "none");
tr.removeClass("grabbed");
}
$(document).mousemove(move).mouseup(up);
});
</script>
Nota si == 0
e i > 0
ignora la prima fila, che per me contiene TH
tag. Sostituisci alert
con la tua logica "trascinamento finito".
Questo non è chiaro dalla tua domanda. Sai che c'è un pulsante "modifica", giusto? –
puoi condividere tutto il tuo codice per il fatto che ho lo stesso problema. –