分页boot—+angu
来源:互联网 发布:cdn网络加速 书 编辑:程序博客网 时间:2024/06/18 07:37
目前在做一个java web页面,没有使用到框架的分页,所以需要自己实现分页,就想到了用angularjs来实现分页,数据通过ajax从后台获取。
插件
百度了一下,看到一个比较漂亮的插件,就直接用该插件,并修改了部分细节,使得适合我的项目,该插件地址是:(https://github.com/miaoyaoyao/AngularJs-UI)
效果图
使用方法
- 在网页的头部引入angularjs、bootstarp以及该插件,该分页插件主要是ng-pagination.css以及ng-pagination.js
<link rel="stylesheet" href="/nutz-test/static/bootstrap/bootstrap.min.css"><link rel="stylesheet" href="/nutz-test/static/angular/ng-pagination.css"><script src="/nutz-test/static/jquery/jquery.min.js"></script><script src="/nutz-test/static/angular/angular.min.js"></script><script src="/nutz-test/static/angular/ng-pagination.js"></script><script src="/nutz-test/static/bootstrap/bootstrap.min.js"></script>
- 表格代码以及分页代码
<div id="app" ng-app="myApp" ng-controller="myCtrl"> <div style="overflow: auto; width: 100%;"> <table class="table table-hover table-striped table-bordered" id="j-table"> <thead> <tr> <th>姓名</th> <th>年龄</th> <th>电话</th> <th>职位</th> </tr> </thead> <tbody> <tr ng-repeat="item in list"> <th title="{{item.name}}">{{item.name}}</th> <th title="{{item.age}}">{{item.age}}</th> <th title="{{item.tel}}">{{item.tel}}</th> <th title="{{item.position}}">{{item.position}}</th> </tr> </tbody> </table> </div><!-- 这里引用插件的分页--> <div class="pager"> <pager page-count="pageCount" current-page="currentPage" on-page-change="onPageChange()" first-text="首页" next-text="下一页" prev-text="上一页" last-text="尾页" show-goto="true" goto-text="跳转到"></pager> </div></div>
- javascript代码部分
分页的重点是从后台获取数据,只需把pageSize(每页显示数目),以及pageIndex(当前页数)通过post请求传到后台即可。后台返回实际的数据以及pageCount(页数)给前台即可。其中,onPageChange()方法是点击页码后去通过ajax从后台获取数据,myinit()方法是第一次请求该页面时进行初始化。$scope.currentPage就是页数,例如当你点击下一页的时候,它就会加一,然后就可以通过post请求去后台取下一页的数据了。
<script type="text/javascript">var app = angular.module('myApp', ['ng-pagination']);app.controller('myCtrl', ['$scope', function ($scope) { $scope.onPageChange = function() { // ajax request to load data console.log($scope.currentPage); //这里是post请求去后台取数据 $.ajax({ type:"post", url:'/nutz-test/show/pagination', data:{ "pageSize":5, "pageIndex":$scope.currentPage }, dataType:"json", success:function(data){ $scope.$apply(function () { $scope.list = data.list; $scope.pageCount = data.pageCount; }); } }) }; //初始化,设置为第一页,每页显示5条 $scope.myinit = function(){ $.ajax({ type:"post", url:'/nutz-test/show/pagination', data:{ "pageSize":5, "pageIndex":1 }, dataType:"json", success:function(data){ $scope.$apply(function () { $scope.list = data.list; $scope.pageCount = data.pageCount; }); } }) }; $scope.myinit();}]);</script>
注意事项
- 该插件在只有一页的情况会出现分页插件加载不出来的情况,因此需要修改ng-pagination.js的代码。
打开ng-pagination.js,定位到最后的template,修改pageCount>=1,如下图所示。
- 在ie浏览器和360浏览器不支持跳转功能,原因是ie和360没有number.isNaN()方法,因此需要修改分页插件的该方法,改为isNaN()。
定位到ng-pagination.js的Number.isNaN()方法,把该方法修改为下图所示。
作者:白虎先生
链接:http://www.jianshu.com/p/c39430338e5f
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
阅读全文
0 0
- 分页boot—+angu
- spring boot分页组件
- Spring boot分页
- Spring Boot+Mybatis+Pagehelper分页
- spring boot mybatis+分页配置
- Spring Boot入门教程-数据分页
- Spring Boot+Mybatis+Pagehelper分页
- Spring boot 搭建个人博客系统(四)——文章的发布和分页显示
- Spring Boot集成MyBatis与分页插件
- eayui结合Spring Boot实现客户端分页
- angular+bootstrap+spring boot实现分页
- spring-boot 分页查询(关联表)
- 分页查询spring boot+spring data+ajax
- spring-boot 分页查询(关联表)
- Spring Boot集成MyBatis与分页插件
- spring boot之mybatis分页多种方法
- spring boot和mybatis集成分页插件
- Spring boot分页显示数据(1)
- 单链表判断环路及环路的入口
- linux netstat
- tensorflow实现MNIST数据集识别
- 2016-08-14-京东笔试和面试(Java方向)
- 判断一个数是不是另一个数的整数次幂,python实现
- 分页boot—+angu
- 填坑之css中的换行与空白
- Android中shape属性详解
- Linux-进程状态&僵尸进程&孤儿进程
- Eclipse安装Maven后JRE警告
- iOS下拉九宫格、百思不得姐项目、微信对话框等源码
- layui实现table加载
- Docker 是什么
- 聪明人喜欢挑战性,高难度excel操作技巧你会几个?