TableDnD
Installation
TableDnD is easy to install:
npm install --save tablednd
or
yarn add tablednd
or
bower install https://github.com/isocra/TableDnD.git
Alternatively you can simply reference from CDNJS:
or
You'll also need to include jQuery before you include this plugin (so that jQuery is defined).
Getting Started
Let's create a simple table. The HTML for the table is very straight forward (no Javascript, pure HTML, we haven't added thead
or tbody
elements, but it works fine with these too):
1Onesome text 2Twosome text 3Threesome text 4Foursome text 5Fivesome text 6Sixsome text
To add in the "draggability" all we need to do is add a line to the $(document).ready(...)
function as follows:
Basically we get the table element and call tableDnD
. If you try this, you'll see that the rows are now draggable.
In the example above we're not setting any parameters at all so we get the default settings. There are a number of parameters you can set in order to control the look and feel of the table and also to add custom behaviour on drag or on drop. The parameters are specified as a map in the usual way and are described the full documentation:
You can also play and experiment with TableDnD using this jsFiddle. Here you get the documentation, plus live examples.