刚开始学习avalon,项目需要就尝试写了个分页控件Pager.js;基于BootStrap样式这个大家都很熟悉

在这里推荐下国产前端神器avalon;确实好用,帮我解决了很多前端问题。

不多说了,代码贴上:

 /**
  * options.id avalon 所需要的$id
  * options.total 总记录数
  * options.rows 行数
  * options.callback
  */
 var Pager=function(options){
     var _this=this;
     _this.callback=options.callback||function(){};
     _this.model=avalon.define({
         $id:options.id,
         currentPage:3,
         rows:10,
         totalRecord:100,
         totalPage:10,
         list:[],
         liPageNums:3,
         init:function(options){//初始化
             _this.model.reset(options);
             _this.model.currentPage=1;

         },
         jump:function(page){//界面跳转
             _this.callback.call(_this,page,_this.model.rows);
             _this.model.currentPage=page;
             _this.model.refresh();
             //alert(page);
         },
         prev:function(){
             if(_this.model.currentPage-1<1)return;
             _this.model.jump(_this.model.currentPage-1);
         },
         next:function(){
             if(_this.model.currentPage+1>_this.model.totalPage)return;
             _this.model.jump(_this.model.currentPage+1);
         },
         refresh:function(){//刷新分页工具栏,计算显示内容
             _this.model.list=[];
             var ll=new Array();
             var cp=_this.model.currentPage;
             for(var i=_this.model.liPageNums;i>0;i--){
                 ll.push(cp-i);
             }
             ll.push(cp);
             for(var i=1;i<=_this.model.liPageNums;i++){
                 ll.push(cp+i);
             }
             while(ll[0]<1){
                 for(var i=0;i<ll.length;i++){
                     ll[i]=ll[i]+1;
                 }
             }
             while(ll[ll.length-1]>_this.model.totalPage){
                 for(var i=0;i<ll.length;i++){
                     ll[i]=ll[i]-1;
                 }
             }
             for(var i=0;i<ll.length;i++){
                 if(ll[i]>=1&&ll[i]<=_this.model.totalPage){
                     _this.model.list.push(ll[i]);
                 }
             }
         },
         /**
          * options.total 总记录数
          * options.rows 每页记录数
          */
         reset:function(options){//数据加载后可按需要重置
             _this.model.rows=options.rows||_this.model.rows;
             _this.model.totalRecord=options.total||0;
             _this.model.totalPage=_this.model.totalRecord%_this.model.rows==0?_this.model.totalRecord/_this.model.rows:parseInt(_this.model.totalRecord/_this.model.rows+1);
             _this.model.refresh();
         }
     });
     _this.getModel=function(){return _this.model;};
     _this.model.init(options);
 };

HTML

 <div class="col-md-12">
            <div class="m-page-footer" ms-controller="footer">
             <table width="100%">
                 <tr>
                 <td>
                     <div class="pages_info pull-left">显示 {{(currentPage-1)*rows+1}} 到 {{currentPage*rows>totalRecord?totalRecord:currentPage*rows}} 项,共 {{totalRecord}} 项 </div>
                 </td>
                 <td style="text-align:right;">
                     <div class="dataTables_paginate paging_simple_numbers pages_num">
                         <ul class="pagination" style="margin:0;">
                             <li class="paginate_button previous" ms-class="disabled:currentPage<=1" aria-controls="editable" tabindex="0" id="editable_previous"><a href="javascript:;" ms-click="prev">上一页</a></li>
                             <li class="paginate_button " aria-controls="editable" tabindex="0" ms-repeat="list" ms-class="active:el==currentPage"><a href="javascript:;" ms-click="jump(el)">{{el}}</a></li>
                             <li class="paginate_button next" ms-class="disabled:currentPage>=totalPage" aria-controls="editable" tabindex="0" id="editable_next"><a href="javascript:;" ms-click="next">下一页</a></li>
                         </ul>
                     </div>
                 </td>
                 </tr>
             </table>
         </div>
   </div>

调用代码,callbakl回调指向列表刷新方法reloadGrid,function reloadGrid(page,rows)

    var pager=new Pager({id:"footer",rows:20,callback:reloadGrid});

     $.post("e",params,function(json){
            model.list=json.rows;
            pager.getModel().reset({total:json.total});

        },"json");    

最终效果:

基于avalon+jquery做的bootstrap分页控件的更多相关文章

  1. 基于jquery扩展漂亮的分页控件(ajax)

    分页控件式大家在熟悉不过的控件,很多情况下都需要使用到分页控件来完成列表数据加载操作,在很多分页控件中有的编写麻烦,有的应用扩展比较复杂,有的分页控件样式比较丑陋,有的分页控件用户体验操作比较简单等等 ...

  2. jQuery Pagination Plugin ajax分页控件

    <html> <body> <div id="datagrid"> </div> <div id="paginati ...

  3. 基于WPF系统框架设计(10)-分页控件设计

    背景 最近要求项目组成员开发一个通用的分页组件,要求是这个组件简单易用,通用性,兼容现有框架MVVM模式,可是最后给我提交的成果勉强能够用,却欠少灵活性和框架兼容性. 设计的基本思想 传入数据源,总页 ...

  4. sharepoint 2010 列表数据分页控件介绍 pagination UserControl

    转:http://blog.csdn.net/chenxinxian/article/details/8714391 这里主要是介绍下最近开发的一个sharepoint列表或者文档库的分页控件,并且把 ...

  5. 基于Bootstrap仿淘宝分页控件实现

    .header { cursor: pointer } p { margin: 3px 6px } th { background: lightblue; width: 20% } table { t ...

  6. ajax 分页控件,基于jquery

    /* 分页插件,依赖jQuery库 version: 1.1.0 author: Harrison Cao release date: 2013-09-23 相对 v1.0版本 修正了分页居中 使用方 ...

  7. 基于存储过程的MVC开源分页控件--LYB.NET.SPPager

    摘要 现在基于ASP.NET MVC的分页控件我想大家都不陌生了,百度一下一大箩筐.其中有不少精品,陕北吴旗娃杨涛大哥做的分页控件MVCPager(http://www.webdiyer.com/)算 ...

  8. MvcPager分页控件以适用Bootstrap

    随笔- 9  文章- 0  评论- 33  修改MvcPager分页控件以适用Bootstrap 效果(含英文版,可下载)   软件开发分页效果必不可少,对于Asp.Net MVC 而言,MvcPag ...

  9. jquery 分页控件2

    jquery 分页控件(二) 上一章主要是关于分页控件的原理,代码也没有重构.在这一章会附上小插件的下载链接,插件主要就是重构逻辑部分,具体可以下载源文件看下,源代码也有注释.为了测试这个插件是能用的 ...

随机推荐

  1. 聊聊、Mybatis XML

    引入相应的依赖包 <dependency><groupId>org.mybatis</groupId><artifactId>mybatis-sprin ...

  2. 【现代程序设计】homework-01

    HOMEWORK-01 1) 建立 GitHub 账户, 把课上做的 “最大子数组之和” 程序签入 已完成. 2) 在 cnblogs.com 建立自己的博客. 写博客介绍自己的 GitHub 账户. ...

  3. Offer 收割编程练习赛 87B 方圆距离

    与坐标轴平行的矩形和圆的位置关系. 分两种情况. 圆与矩形交集不为空 此时答案为零.问题归结为如何判断圆与矩形交集不为空. 先排除矩形顶点在圆内或圆心在矩形内. 此时,若矩形与圆交集不为空,则必有矩形 ...

  4. 2017 多校4 Matching In Multiplication(二分图)

    Matching In Multiplication 题解: 首先如果一个点的度数为1,那么它的匹配方案是固定的,继而我们可以去掉这一对点.通过拓扑我们可以不断去掉所有度数为1的点. 那么剩下的图中左 ...

  5. Installing Wine 1.5: configure: error: Cannot build a 32-bit program, you need to install 32-bit development libraries(转载)

    Installing Wine 1.5: configure: error: Cannot build a 32-bit program, you need to install 32-bit dev ...

  6. svn installation

    # yum install mod_dav_svn.x86_64 subversion-svn2cl.noarch=========================================== ...

  7. 云服务器基本环境配置(php5.6+mysql+nginx)

    1.安装nginx sudo apt-get install nginx nginx 基本配置 server{ listen ; server_name www.xxxxxx.cn; root /va ...

  8. OpenGL ES课程VI之纹理贴图(原文对照)

    http://www.educity.cn/wenda/92368.html OpenGL ES教程VI之纹理贴图(原文对照) OpenGL ES Tutorial for Android – Par ...

  9. Linux操作系统的权限代码分析【转】

    转自:http://blog.csdn.net/lixuyuan/article/details/6217502 现在关于内核的书很少涉及到Linux内核的安全,内核安全大概包括了密码学实现(cryp ...

  10. Scala学习随笔——Scala起步

    实验楼学习Scala语言的笔记,课程网址为https://www.shiyanlou.com/courses/490 一.Scala简介 Scala 是一门多范式的编程语言,类似于 Java .设计初 ...