easyUI 数据表格客户分页

Posted Wit_tang

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了easyUI 数据表格客户分页相关的知识,希望对你有一定的参考价值。


  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Client Side Pagination in DataGrid - jQuery EasyUI Demo</title>
  6. <link rel="stylesheet" type="text/css" href="../../themes/default/easyui.css">
  7. <link rel="stylesheet" type="text/css" href="../../themes/icon.css">
  8. <link rel="stylesheet" type="text/css" href="../demo.css">
  9. <script type="text/javascript" src="../../jquery.min.js"></script>
  10. <script type="text/javascript" src="../../jquery.easyui.min.js"></script>
  11. </head>
  12. <body>
  13. <h2>Client Side Pagination in DataGrid</h2>
  14. <p>This sample shows how to implement client side pagination in DataGrid.</p>
  15. <div style="margin:20px 0;"></div>
  16. <table id="dg" title="Client Side Pagination" style="width:700px;height:300px" data-options="
  17. rownumbers:true,
  18. singleSelect:true,
  19. autoRowHeight:false,
  20. pagination:true,
  21. pageSize:10">
  22. <thead>
  23. <tr>
  24. <th field="inv" width="80">Inv No</th>
  25. <th field="date" width="100">Date</th>
  26. <th field="name" width="80">Name</th>
  27. <th field="amount" width="80" align="right">Amount</th>
  28. <th field="price" width="80" align="right">Price</th>
  29. <th field="cost" width="100" align="right">Cost</th>
  30. <th field="note" width="110">Note</th>
  31. </tr>
  32. </thead>
  33. </table>
  34. <script>
  35. function getData()
  36. var rows = [];
  37. for(var i=1; i<=800; i++)
  38. var amount = Math.floor(Math.random()*1000);
  39. var price = Math.floor(Math.random()*1000);
  40. rows.push(
  41. inv: 'Inv No '+i,
  42. date: $.fn.datebox.defaults.formatter(new Date()),
  43. name: 'Name '+i,
  44. amount: amount,
  45. price: price,
  46. cost: amount*price,
  47. note: 'Note '+i
  48. );
  49. return rows;
  50. function pagerFilter(data)
  51. if (typeof data.length == 'number' && typeof data.splice == 'function') // is array
  52. data =
  53. total: data.length,
  54. rows: data
  55. var dg = $(this);
  56. var opts = dg.datagrid('options');
  57. var pager = dg.datagrid('getPager');
  58. pager.pagination(
  59. onSelectPage:function(pageNum, pageSize)
  60. opts.pageNumber = pageNum;
  61. opts.pageSize = pageSize;
  62. pager.pagination('refresh',
  63. pageNumber:pageNum,
  64. pageSize:pageSize
  65. );
  66. dg.datagrid('loadData',data);
  67. );
  68. if (!data.originalRows)
  69. data.originalRows = (data.rows);
  70. var start = (opts.pageNumber-1)*parseInt(opts.pageSize);
  71. var end = start + parseInt(opts.pageSize);
  72. data.rows = (data.originalRows.slice(start, end));
  73. return data;
  74. $(function()
  75. $('#dg').datagrid(loadFilter:pagerFilter).datagrid('loadData', getData());
  76. );
  77. </script>
  78. </body>
  79. </html>

以上是关于easyUI 数据表格客户分页的主要内容,如果未能解决你的问题,请参考以下文章

easyUI数据表格datagrid之分页

Jquery EasyUI datagrid后台数据表格生成及分页详解

easyui的pagination分页可以不用datagrid吗

EasyUI基础入门之Pagination(分页)

为啥easyui-datagrid分页控件把所有的都遮住了?

为啥easyui-datagrid分页控件把所有的都遮住了?