tableDnD实现table里行的拖拽排序

tableDnD是一个能使table里的行能拖动排序的插件。这个插件的主页在Github上,用谷歌去查,百度一下,你什么都不会知道。使用这个插件也很简单,直接给table节点绑定这个插件就行了。

$("#tableId").tableDnD({
      onDragClass:'highlight',
      onDrop:function(table,row){
          console.log('AAA');
      }
});

onDragClass属性标识的是在选中拖动一行时候的样式效果,onDrop方法是表示拖动成功后执行的方法,主要用着两个属性和方法就可以完成需要的功能。这里就可以执行ajax将排序值重组,完成完整的拖动排序功能。如果某一些行不想拖动,只需要给这一行添加class nodrop和nodrag即可。

<tr class="nodrop nodrag">
    <td>10</td> 
    <td>The Lord of the Rings: The Return of the King</td>
    <td>2003</td>
</tr>


整体的效果如下:


完整代码如下所示,里面的tableDnD.js可以再github上下载到。

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Table拖拽测试</title>
    <link href="http://cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
    <style>

body {
    width: 600px;
    margin: 40px auto;
    font-family: 'trebuchet MS', 'Lucida sans', Arial;
    font-size: 14px;
    color: #444;
}

table {
    *border-collapse: collapse; /* IE7 and lower */
    border-spacing: 0;
    width: 100%;    
}

.bordered {
    border: solid #ccc 1px;
    -moz-border-radius: 6px;
    -webkit-border-radius: 6px;
    border-radius: 6px;
    -webkit-box-shadow: 0 1px 1px #ccc; 
    -moz-box-shadow: 0 1px 1px #ccc; 
   
  • 5
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值