Al parecer, la pregunta mal describe el problema de la OP, pero esta pregunta es el resultado de búsqueda superior para arrastrar para reordenar las filas de la tabla, por lo que es w voy a responder.No estaba interesado en traer jQuery UI para algo tan simple, por lo que aquí hay una única solución 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
y i > 0
hace caso omiso de la primera fila, que para mí contiene TH
etiquetas. Reemplace el alert
con su lógica de "arrastre terminado".
Eso no está claro en su pregunta. Usted sabe que hay un botón de "editar", ¿verdad? –
puede compartir su código todo por eso tengo el mismo problema. –