TableDnD

jQuery plug-in to drag and drop rows in HTML tables

Github星跟蹤圖

TableDnD

npm version
CDNJS version
jsDelivr Hits
Reviewed by Hound

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:

<script src="https://cdnjs.cloudflare.com/ajax/libs/TableDnD/0.9.1/jquery.tablednd.js" integrity="sha256-d3rtug+Hg1GZPB7Y/yTcRixO/wlI78+2m08tosoRn7A=" crossorigin="anonymous"></script>

or

<script src="https://cdnjs.cloudflare.com/ajax/libs/TableDnD/0.9.1/jquery.tablednd.js" integrity="sha256-d3rtug+Hg1GZPB7Y/yTcRixO/wlI78+2m08tosoRn7A=" crossorigin="anonymous"></script>

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):

<table id="table-1" cellspacing="0" cellpadding="2">
    <tr id="1"><td>1</td><td>One</td><td>some text</td></tr>
    <tr id="2"><td>2</td><td>Two</td><td>some text</td></tr>
    <tr id="3"><td>3</td><td>Three</td><td>some text</td></tr>
    <tr id="4"><td>4</td><td>Four</td><td>some text</td></tr>
    <tr id="5"><td>5</td><td>Five</td><td>some text</td></tr>
    <tr id="6"><td>6</td><td>Six</td><td>some text</td></tr>
</table>

To add in the "draggability" all we need to do is add a line to the $(document).ready(...) function as follows:

<script type="text/javascript">
$(document).ready(function() {
    // Initialise the table
    $("#table-1").tableDnD();
});
</script>

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.

主要指標

概覽
名稱與所有者isocra/TableDnD
主編程語言HTML
編程語言JavaScript (語言數: 4)
平台
許可證Other
所有者活动
創建於2011-08-31 13:18:42
推送於2025-05-04 10:27:58
最后一次提交2024-10-16 13:04:49
發布數6
最新版本名稱1.0.5 (發布於 2020-11-20 12:56:25)
第一版名稱0.9.1 (發布於 2015-04-23 21:14:17)
用户参与
星數401
關注者數31
派生數370
提交數203
已啟用問題?
問題數63
打開的問題數31
拉請求數60
打開的拉請求數11
關閉的拉請求數55
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?