reload.html 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. <div class="test-table-reload-btn" style="margin-bottom: 10px;">
  17. 搜索ID:
  18. <div class="layui-inline">
  19. <input class="layui-input" name="id" id="test-table-demoReload" autocomplete="off">
  20. </div>
  21. <button class="layui-btn" data-type="reload">搜索</button>
  22. </div>
  23. <table class="layui-hide" id="test-table-reload" lay-filter="user"></table>
  24. <blockquote class="layui-elem-quote">此处由于是静态模拟数据,所以搜索后重载的结果没变,这并非是 BUG。实际使用时改成真实接口并根据搜索的字段筛选出对应的数据即可。</blockquote>
  25. </div>
  26. </div>
  27. </div>
  28. </div>
  29. </div>
  30. <script>
  31. layui.use(['admin', 'table'], function(){
  32. var table = layui.table;
  33. //方法级渲染
  34. table.render({
  35. elem: '#test-table-reload'
  36. ,url: './json/table/user.js'
  37. ,cols: [[
  38. {checkbox: true, fixed: true}
  39. ,{field:'id', title: 'ID', width:80, sort: true, fixed: true}
  40. ,{field:'username', title: '用户名', width:80}
  41. ,{field:'sex', title: '性别', width:80, sort: true}
  42. ,{field:'city', title: '城市', width:80}
  43. ,{field:'sign', title: '签名'}
  44. ,{field:'experience', title: '积分', sort: true, width:80}
  45. ,{field:'score', title: '评分', sort: true, width:80}
  46. ,{field:'classify', title: '职业', width:80}
  47. ,{field:'wealth', title: '财富', sort: true, width:135}
  48. ]]
  49. ,page: true
  50. ,height: 315
  51. });
  52. var $ = layui.$, active = {
  53. reload: function(){
  54. var demoReload = $('#test-table-demoReload');
  55. //执行重载
  56. table.reload('test-table-reload', {
  57. page: {
  58. curr: 1 //重新从第 1 页开始
  59. }
  60. ,where: {
  61. key: {
  62. id: demoReload.val()
  63. }
  64. }
  65. });
  66. }
  67. };
  68. $('.test-table-reload-btn .layui-btn').on('click', function(){
  69. console.log("22222")
  70. var type = $(this).data('type');
  71. active[type] ? active[type].call(this) : '';
  72. });
  73. });
  74. </script>