cellEdit.html 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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-cellEdit" lay-filter="test-table-cellEdit"></table>
  17. </div>
  18. </div>
  19. </div>
  20. </div>
  21. </div>
  22. <script>
  23. layui.use(['admin', 'table'], function(){
  24. var table = layui.table;
  25. table.render({
  26. elem: '#test-table-cellEdit'
  27. ,url: './json/table/demo.js'
  28. ,cols: [[
  29. {type:'checkbox'}
  30. ,{field:'id', title:'ID', width:80, sort: true}
  31. ,{field:'username', title:'用户名', width:120, sort: true, edit: 'text'}
  32. ,{field:'email', title:'邮箱', edit: 'text', minWidth: 150}
  33. ,{field:'sex', title:'性别', width:80, edit: 'text'}
  34. ,{field:'city', title:'城市', edit: 'text', minWidth: 100}
  35. ,{field:'experience', title:'积分', sort: true, edit: 'text'}
  36. ]]
  37. })
  38. //监听单元格编辑
  39. table.on('edit(test-table-cellEdit)', function(obj){
  40. var value = obj.value //得到修改后的值
  41. ,data = obj.data //得到所在行所有键值
  42. ,field = obj.field; //得到字段
  43. layer.msg('[ID: '+ data.id +'] ' + field + ' 字段更改为:'+ value, {
  44. offset: '15px'
  45. });
  46. });
  47. });
  48. </script>