刚开始学习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. 稀疏矩阵相乘-Python版

                                          稀疏矩阵相乘-Python版 Given two sparse matrices A and B, return the r ...

  2. c++知识点总结--静态与动态联编

    静态联编是指在编译阶段就将函数实现和函数调用关联起来,因此静态联编也叫早绑定,在编译阶段就必须了解所有的函数或模块执行所需要检测的信息,它对函数的选择是基于指向对象的指针(或者引用)的类型   动态联 ...

  3. 团队Alpha版本冲刺(六)

    目录 组员情况 组员1(组长):胡绪佩 组员2:胡青元 组员3:庄卉 组员4:家灿 组员5:凯琳 组员6:翟丹丹 组员7:何家伟 组员8:政演 组员9:黄鸿杰 组员10:刘一好 组员11:何宇恒 展示 ...

  4. HTML5初识Canvas

    HTML5初识Canvas <!DOCTYPE html> <html lang="en"> <head> <meta charset=& ...

  5. Spring MVC表单标签

    从Spring 2.0开始,Spring MVC开始全面支持表单标签,通过Spring MVC表单标签,我们可以很容易地将控制器相关的表单对象绑定到HTML表单元素中. form标签     和使用任 ...

  6. Hexo-设置阅读全文

    最近使用Hexo搭建了自己的博客,并且使用了简洁但是强大的NexT主题.这里介绍一下NexT主题下设置在首页显示一篇文章的简介,在简介后面提供一个链接阅读全文来进入文章的详情页.效果请看 我的小窝 在 ...

  7. SQLServer对视图或函数’XXX’的更新或插入失败,因其包含派生域或常量域解决

    原因:视图view不允许修改. 解决:重新创建一个相同结构内容的表. 解释:因为所创建的视图对其属性值进行了计算的其他形式上的改变,而对视图的更改最终表现为对表的更改而表中不存在视图的某一属性,或属性 ...

  8. Web 安全概念

    Web 安全概念 Web 应用中存在很多安全风险,这些风险会被黑客利用,轻则篡改网页内容,重则窃取网站内部数据,更为严重的则是在网页中植入恶意代码,使得用户受到侵害.常见的安全漏洞如下: XSS 攻击 ...

  9. php的post

    代码的顺序不能乱,否则会提交错误 $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HE ...

  10. Create Windows Server 2008 cluster from the command line

    How to create a Windows Server 2008 cluster from the command line? Creating a cluster in Server 2008 ...