onrow.html 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <title>监听行事件 - 数据表格</title>
  2. <div class="layui-card layadmin-header">
  3. <div class="layui-breadcrumb" lay-filter="breadcrumb">
  4. <a lay-href="">主页</a>
  5. <a><cite>组件</cite></a>
  6. <a><cite>数据表格</cite></a>
  7. <a><cite>监听行事件</cite></a>
  8. </div>
  9. </div>
  10. <div class="layui-fluid">
  11. <div class="layui-row layui-col-space15">
  12. <div class="layui-col-md12">
  13. <div class="layui-card">
  14. <div class="layui-card-header">监听行事件</div>
  15. <div class="layui-card-body">
  16. <table class="layui-hide" id="test-table-onrow" lay-filter="test-table-onrow"></table>
  17. </div>
  18. </div>
  19. </div>
  20. </div>
  21. </div>
  22. <script>
  23. layui.use(['admin', 'table'], function(){
  24. var admin = layui.admin
  25. ,table = layui.table;
  26. table.render({
  27. elem: '#test-table-onrow'
  28. ,url:'/test/table/demo1.json'
  29. ,cols: [[
  30. {field:'id', title:'ID', width:80, fixed: 'left', unresize: true, sort: true}
  31. ,{field:'username', title:'用户名', width:120}
  32. ,{field:'email', title:'邮箱', width:150, templet: function(res){
  33. return '<em>'+ res.email +'</em>'
  34. }}
  35. ,{field:'sex', title:'性别', width:80, sort: true}
  36. ,{field:'city', title:'城市', width:100}
  37. ,{field:'sign', title:'签名'}
  38. ,{field:'experience', title:'积分', width:80, sort: true}
  39. ,{field:'ip', title:'IP', width:120}
  40. ,{field:'logins', title:'登入次数', width:100, sort: true}
  41. ,{field:'joinTime', title:'加入时间', width:120}
  42. ]]
  43. ,page: true
  44. });
  45. //监听行单击事件(单击事件为:rowDouble)
  46. table.on('row(test-table-onrow)', function(obj){
  47. var data = obj.data;
  48. layer.alert(JSON.stringify(data), {
  49. title: '当前行数据:'
  50. });
  51. //标注选中样式
  52. obj.tr.addClass('layui-table-click').siblings().removeClass('layui-table-click');
  53. });
  54. });
  55. </script>