时间:2021-05-28
本文实例为大家分享了Angular 分页的具体代码,供大家参考,具体内容如下
1、Html
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width" /> <title>MyPagination</title> <link href="//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet" /> <script src="~/Scripts/angular.js"></script> <script src="~/Scripts/ui-bootstrap-tpls-0.13.0.min.js"></script> <script> var readyDataUrl = '@Url.Content("~/StudentManage/GetPageList")'; var loadDataUrl = '@Url.Content("~/StudentManage/GetPageList")'; var app = angular.module('app', ['ui.bootstrap']); app.controller('ctrl', ['$log', '$http', '$scope', function ($log, $http, $scope) { $scope.reportData = []; $scope.maxSize = 7; $scope.currentPage = 0; $scope.totalItems = 0; $scope.pageChanged = function () { //showLoading("正在查询"); $http.post(loadDataUrl, { pageIndex: $scope.currentPage, pageSize: 10, name: "" }) .then(function (result) { $scope.reportData = result.data.Data; $scope.totalItems = result.data.recordTotal; }).catch(function (error) { $log.error('error:' + error); }).finally(function () { //closeLoading(); }); } $scope.Inital = function () { //showLoading("正在查询"); $http.post(readyDataUrl, { pageIndex: $scope.currentPage, pageSize: 10, name: "" }).then(function (result) { $scope.reportData = result.data.Data; $scope.totalItems = result.data.recordTotal; //closeLoading(); }).catch(function (error) { $log.error('error:' + error); }).finally(function () { }); } $scope.Inital(); $scope.search = function () { //showLoading("正在查询"); $http.post(loadDataUrl, {}) .then(function (result) { $scope.reportData = result.data.Data; $scope.totalItems = result.data.recordTotal; }).catch(function (error) { $log.error('error:' + error); }).finally(function () { //closeLoading(); }); } }]); </script> </head> <body> <div ng-app="app" ng-controller="ctrl"> <div class="form-group" id="toolbar"> <table> <tr> <td style="padding-left:10px;"> <button type="button" class="btn btn-success btn-sm" id="btnSearch" ng-click="search()">查询</button> </td> </tr> </table> <div class="bootstrap-table"> <div class="fixed-table-container" style="padding-bottom: 0px;"> <div class="table-responsive"> <table class="table table-condensed table-hover table-striped"> <thead> <tr> <th><div class="th-inner">序号</div></th> <th><div class="th-inner">姓名</div></th> <th><div class="th-inner">电话</div></th> <th><div class="th-inner">邮箱</div></th> <th><div class="th-inner">年龄</div></th> <th><div class="th-inner">国家</div></th> <th><div class="th-inner">城市</div></th> </tr> </thead> <tbody> <tr ng-repeat="o in reportData"> <td><span ng-bind="o.Id"></span></td> <td><span ng-bind="o.Name"></span></td> <td><span ng-bind="o.Telephone"></span></td> <td><span ng-bind="o.Email"></span></td> <td><span ng-bind="o.Age"></span></td> <td><span ng-bind="o.Country"></span></td> <td><span ng-bind="o.City"></span></td> </tr> </tbody> </table> </div> </div> </div> <pagination class="pagination-sm pull-right" ng-model="currentPage" total-items="totalItems" max-size="7" ng-change="pageChanged()" force-ellipses="true" num-pages="numPages" boundary-link-numbers="true" boundary-links="false" @*是否显示第一个/最后一个按钮*@ rotate="false" previous-text="‹" next-text="›"> </pagination> </div> </div> </body> </html>2、Action
[HttpPost] public JsonResult GetPageList(int pageIndex, int pageSize, string name) { int pageCount = 1; int recordTotal = 0; int topRecordTotal = 0; List<Students> list = new List<Students>(); try { list = svc.GetAllStudent(); recordTotal = list.Count(); pageCount = (int)Math.Ceiling((decimal)recordTotal / pageSize); topRecordTotal = (pageIndex - 1 < 0 ? 0 : pageIndex - 1) * pageSize; list = list.Skip(topRecordTotal).Take(pageSize).ToList(); } catch (Exception) { throw; } return Json(new { pageIndex = pageIndex, pageCount = pageCount, recordTotal = recordTotal, Data = list, }, JsonRequestBehavior.AllowGet); }效果图:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
分页(Pagination),是一种无序列表,Bootstrap像处理其他界面元素一样处理分页。bootstrap-table介绍bootstrap-table
需要用到的jsangular.js(用angular.min.js会导致分页控件不显示)ui-bootstrap-tpls.min.jsangular-anim
我主要讲此代码用于MVC的分布页。先看最终效果最终效果:样式为bootstrap3中的分页“pagination”,如果不使用bootstrap单独提出来并不大
今天我们来看看一种只实现分页没有查询的例子吧,先看效果:采用了Angular-UI中的分页组件,关于Angular-UI如何使用请移步这里https://ang
在AngularJS中使用模态框需要引用的文件:angular.js1.5.5ui.bootstrap-tpls.js0.11.2bootstrap.css3.