<!DOCTYPE html>
<html>
<head>
 <meta charset="UTF-8">
 <title>Client Side Pagination - jQuery EasyUI Demo</title>
 <link rel="stylesheet" type="text/css" href="../../themes/default/easyui.css">
 <link rel="stylesheet" type="text/css" href="../../themes/icon.css">
 <link rel="stylesheet" type="text/css" href="../demo.css">
 <script type="text/javascript" src="../../jquery-1.8.0.min.js"></script>
 <script type="text/javascript" src="../../jquery.easyui.min.js"></script>
</head>
<body>
 <h2>Client Side Pagination</h2>
 <div class="demo-info">
  <div class="demo-tip icon-tip"></div>
  <div>This sample shows how to implement client side pagination in DataGrid.</div>
 </div>
 <div style="margin:10px 0;"></div>
 
 <table id="dg" title="Client Side Pagination" style="width:700px;height:300px" data-options="
    rownumbers:true,
    singleSelect:true,
    autoRowHeight:false,
    pagination:true,
    pageSize:10">
  <thead>
   <tr>
    <th field="inv" width="80">Inv No</th>
    <th field="date" width="100">Date</th>
    <th field="name" width="80">Name</th>
    <th field="amount" width="80" align="right">Amount</th>
    <th field="price" width="80" align="right">Price</th>
    <th field="cost" width="100" align="right">Cost</th>
    <th field="note" width="110">Note</th>
   </tr>
  </thead>
 </table>
 <script>
  function getData(){
   var rows = [];
   for(var i=1; i<=800; i++){
    var amount = Math.floor(Math.random()*1000);
    var price = Math.floor(Math.random()*1000);
    rows.push({
     inv: 'Inv No '+i,
     date: $.fn.datebox.defaults.formatter(new Date()),
     name: 'Name '+i,
     amount: amount,
     price: price,
     cost: amount*price,
     note: 'Note '+i
    });
   }
   return rows;
  }
  
  function pagerFilter(data){
   if (typeof data.length == 'number' && typeof data.splice == 'function'){ // is array
    data = {
     total: data.length,
     rows: data
    }
   }
   var dg = $(this);
   var opts = dg.datagrid('options');
   var pager = dg.datagrid('getPager');
   pager.pagination({
    onSelectPage:function(pageNum, pageSize){
     opts.pageNumber = pageNum;
     opts.pageSize = pageSize;
     pager.pagination('refresh',{
      pageNumber:pageNum,
      pageSize:pageSize
     });
     dg.datagrid('loadData',data);
    }
   });
   if (!data.originalRows){
    data.originalRows = (data.rows);
   }
   var start = (opts.pageNumber-1)*parseInt(opts.pageSize);
   var end = start + parseInt(opts.pageSize);
   data.rows = (data.originalRows.slice(start, end));
   return data;
  }
  
  $(function(){
   $('#dg').datagrid({loadFilter:pagerFilter}).datagrid('loadData', getData());
  });
 </script>
</body>
</html>

最新文章

  1. jqGrid的autoencode参数设置为true在客户端可能引发的编码问题
  2. 学习设计接口api(转)
  3. 关于window.onload,window.onbeforeload与window.onunload
  4. shell 命令
  5. javascript中字符串格式json如何转化成json对象
  6. C++ MFC实现基于RFID读写器的上位机软件
  7. 使用ASP.NET注册工具aspnet_regiis.exe注册IIS
  8. HTTP长轮询和短轮询
  9. SRM DIV1 500pt DP
  10. WebView Cache 缓存清除
  11. 计算机网络基础_01IP地址
  12. JavaScript系统学习小结——变量、作用域和内存问题
  13. 3.QT中QCommandLineParser和QCommandLineOption解析命令行参数
  14. Lambda表达式Contains方法(等价于SQL语句中的like)使用注意事项
  15. [Codeforces441E]Valera and Number
  16. Redis的五种数据类型
  17. 【scrapy】爬虫中报Forbidden by robots.txt
  18. django model 条件过滤 queryset.filter(**condtions) 用法
  19. springmvc 整合shiro
  20. Python学习之路:一天搞定基础部分

热门文章

  1. hadoop优点和缺点
  2. plsql programming 17 过程, 函数与参数
  3. ogre世界坐标鱼屏幕坐标相互转换
  4. 使用Aspose.Cells组件生成Excel文件
  5. HDU 1513 Palindrome
  6. Drawable和Bitmap的区别
  7. BZOJ 1415 聪聪和可可
  8. php 调试工具及学习PHP垃圾回收机制了解引用计数器的概念
  9. (转)Mac OS X写了个rm时将文件放入回收站的小工具
  10. StringUtils判断字符串是否为空的方法