刚开始学习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. 公路建设 (highway.c/cpp/pas)

    2.公路建设 (highway.c/cpp/pas) 在滨海市一共有 n 个城市,编号依次为 1 到 n,它们之间计划修建 m 条双向道路,其中 修建第 i 条道路的费用为 ci. 海霸王作为滨海市公 ...

  2. 如何写出高质量的JavaScript代码

    优秀的Stoyan Stefanov在他的新书中(<Javascript Patterns>)介绍了很多编写高质量代码的技巧,比如避免使用全局变量,使用单一的var关键字,循环式预存长度等 ...

  3. es6+最佳入门实践(3)

    3.数组扩展 3.1.扩展运算符 扩展运算符用三个点(...)表示,从字面上理解,它的功能就是把数组扩展开来,具体形式如下: let arr = [1, 2, 3]; console.log(...a ...

  4. [LeetCode] Combinations 回溯

    Given two integers n and k, return all possible combinations of k numbers out of 1 ... n. For exampl ...

  5. TemplateBinding和Binding

    TemplateBinding是Binding的一个轻量级版本,它失去了成熟版本Binding的很多功能,比如继承内容引用(inheritence context referencing),Relat ...

  6. zlib编译不过(Error A2070)解决方法(转)

    原文转自 http://dearymz.blog.163.com/blog/static/2056574200871010027435/ 1.zlib是个很牛的东东,从http://www.zlib. ...

  7. Linux SPI总线和设备驱动架构之一:系统概述【转】

    转自:http://blog.csdn.net/droidphone/article/details/23367051/ 版权声明:本文为博主原创文章,未经博主允许不得转载.   目录(?)[-] 硬 ...

  8. selenium的动作链 actionchains

    click(on_element=None) ——单击鼠标左键 click_and_hold(on_element=None) ——点击鼠标左键,不松开 context_click(on_elemen ...

  9. Daemon Process

    Daemon Process 守护进程(Daemon)是运行在后台的一种特殊进程.它独立于控制终端并且周期性地执行某种任务或等待    处理某些发生的事件.守护进程是一种很有用的进程.     Lin ...

  10. 3.Centos-Docker-rancher

    1.安装mysql,设置密码 docker run -d --name mysqldb -e MYSQL_ROOT_PASSWORD=密码 mysql:latest --character-set-s ...