2f11b9676c5ff427a5f0fd4496957988389f0a56.svn-base 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. }
  50. return rows;
  51. }
  52. function pagerFilter(data){
  53. if (typeof data.length == 'number' && typeof data.splice == 'function'){ // is array
  54. data = {
  55. total: data.length,
  56. rows: data
  57. }
  58. }
  59. var dg = $(this);
  60. var opts = dg.datagrid('options');
  61. var pager = dg.datagrid('getPager');
  62. pager.pagination({
  63. onSelectPage:function(pageNum, pageSize){
  64. opts.pageNumber = pageNum;
  65. opts.pageSize = pageSize;
  66. pager.pagination('refresh',{
  67. pageNumber:pageNum,
  68. pageSize:pageSize
  69. });
  70. dg.datagrid('loadData',data);
  71. }
  72. });
  73. if (!data.originalRows){
  74. data.originalRows = (data.rows);
  75. }
  76. var start = (opts.pageNumber-1)*parseInt(opts.pageSize);
  77. var end = start + parseInt(opts.pageSize);
  78. data.rows = (data.originalRows.slice(start, end));
  79. return data;
  80. }
  81. $(function(){
  82. $('#dg').datagrid({loadFilter:pagerFilter}).datagrid('loadData', getData());
  83. });
  84. </script>
  85. </body>
  86. </html>