JSFiddle - React, Tailwind, and code Playground
HTML
<div id="diagnoses_zelf">
</div>
CSS
table {
border : 1px solid black;
}
JavaScript
jQuery.tableDnD = {
/** Keep hold of the current table being dragged */
currentTable: null,
/** Keep hold of the current drag object if any */
dragObject: null,
/** The current mouse offset */
mouseOffset: null,
/** Remember the old value of Y so that we don't do too much processing */
oldY: 0,
/** Actually build the structure */
build: function (options) {
// Make sure options exists
options = options || {};
// Set up the defaults if any
this.each(function () {
// Remember the options
this.tableDnDConfig = {
onDragStyle: options.onDragStyle,
onDropStyle: options.onDropStyle,
// Add in the default class for whileDragging
onDragClass: options.onDragClass ? options.onDragClass : "tDnD_whileDrag",
onDrop: options.onDrop,
onDragStart: options.onDragStart,
scrollAmount: options.scrollAmount ? options.scrollAmount : 5
};
// Now make the rows draggable
jQuery.tableDnD.makeDraggable(this);
});
// Now we need to capture the mouse up and mouse move event
// We can use bind so that we don't interfere with other event handlers
jQuery(document)
.bind('mousemove', jQuery.tableDnD.mousemove)
.bind('mouseup', jQuery.tableDnD.mouseup);
// Don't break the chain
return this;
},
/** This function makes all the rows on the table draggable apart from those marked as "NoDrag" */
makeDraggable: function (table) {
// Now initialise the rows
var rows = table.rows; //getElementsByTagName("tr")
var config = table.tableDnDConfig;
for (var i = 0; i < rows.length; i++) {
// To make non-draggable rows, add the nodrag class (eg for Category and Header rows)
// inspired by John Tarr and Famic
var...