log1.html 3.87 KB
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>在线调试</title>
  <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <link rel="stylesheet" href="layui/css/layui.css" media="all"/>
  <link rel="stylesheet" href="soulTable.css" media="all"/>
</head>
<body> 
<script type="text/javascript" src="layui/layui.js"></script>
<div class="layui-btn-group demoTable" style="margin-bottom: 10px;">
  <!-- <button class="layui-btn" data-type="parseTable">立即转化为数据表格</button> -->
</div>
 
<script type="text/html" id="toolbarDemo">
  <div class="layui-row">

<div class="layui-col-md10 layui-col-sm9 layui-col-xs6" style="text-align: right;">            
  <div class="layui-input-inline yutons-btn-margin-right" style="margin-right: 0px;">
      <span class="layui-inline yutons-header-tool" title="筛选列" lay-event="LAYTABLE_COLS">
                  <i class="layui-icon layui-icon-cols"></i></span>
      <!-- <span class="layui-inline yutons-header-tool" title="打印" lay-event="LAYTABLE_PRINT">
                  <i class="layui-icon layui-icon-print"></i>
      </span> -->
  </div>
</div>
</div>
</script> 

<script type="text/html" id="typeTpl">
  <button class="layui-btn" id="myButton"   >点击我</button>
</script>
<table lay-filter="parse-table-demo">
  <thead>
    <tr>
      <th lay-data="{field:'username', width:200,templet: '#typeTpl'}">昵称</th>
      <th lay-data="{field:'joinTime', width:150}">加入时间</th>
      <th lay-data="{field:'sign', minWidth: 180}">签名</th>
    </tr> 
  </thead>
  <tbody>
    <tr>
      <td></td>
      <td>2016-11-28</td>
      <td>人生就像是一场修行 A</td>
    </tr>
    <tr>
      <td>贤心2</td>
      <td>2016-11-29</td>
      <td>人生就像是一场修行 B</td>
    </tr>
    <tr>
      <td>贤心3</td>
      <td>2016-11-30</td>
      <td>人生就像是一场修行 C</td>
    </tr>
  </tbody>
</table>


<script>
      // 自定义模块
  layui.config({
    base: 'ext/',   // 模块目录
    version: 'v1.6.4'
  }).extend({             // 模块别名
    soulTable: 'soulTable'
  });



   layui.use(['form', 'table','soulTable'], function () {
  var table = layui.table,
        form = layui.form,
        soulTable = layui.soulTable;
     
  table.init('parse-table-demo', { //转化静态表格
       height: 'full-500'
       ,toolbar : '#toolbarDemo', //操作1:启用自定义模板表格头部工具栏
								defaultToolbar : []//操作2:隐藏头部工具栏右侧的图标

        ,height: 500
        ,rowDrag: {/*trigger: 'row',*/ done: function(obj) {
            // 完成时(松开时)触发
            // 如果拖动前和拖动后无变化,则不会触发此方法
            console.log(obj.row) // 当前行数据
            console.log(obj.cache) // 改动后全表数据
            console.log(obj.oldIndex) // 原来的数据索引
            console.log(obj.newIndex) // 改动后数据索引
        }}
        ,drag: {/*trigger: 'row',*/ done: function(obj) {
          console.log('test11111888',obj)
            // // 完成时(松开时)触发
            // // 如果拖动前和拖动后无变化,则不会触发此方法
            // console.log(obj.row) // 当前行数据
            // console.log(obj.cache) // 改动后全表数据
            // console.log(obj.oldIndex) // 原来的数据索引
            // console.log(obj.newIndex) // 改动后数据索引
        }}
        ,totalRow: true
       ,done: function () {
            soulTable.render(this)
       
        }
     });  
     form.on('switch(rowDragSwitch)', function(data){
      soulTable.suspend('myTable', 'rowDrag', true)
      soulTable.suspend('myTable', 'drag', true)

    });
    $(document).on('click','#myButton',function(){
            layer.msg('hello');
            alert("111111");
        });

})
</script>

</body>
</html>