AngularJs的UI組件ui-Bootstrap分享(五)——Pager和Pagination

來源:互聯網
上載者:User

標籤:angular   span   唯讀   null   label   pts   tle   $scope   組件   

原文地址:http://www.cnblogs.com/pilixiami/p/5634405.html

ui-bootstrap中有兩個分頁控制項,一個是輕量級的Pager,只有上一頁和下一頁的功能,另一個是功能完整的Pagination,除了上一頁和下一頁,還可以選擇首頁和最後頁,並且支援多種頁數的顯示方式。

這是Pager的例子:

 

<!DOCTYPE html><html ng-app="ui.bootstrap.demo" xmlns="http://www.w3.org/1999/xhtml"><head>    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />    <link href="/Content/bootstrap.css" rel="stylesheet" />    <title></title>    <script src="/Scripts/angular.js"></script>    <script src="/Scripts/ui-bootstrap-tpls-1.3.2.js"></script>    <script>        angular.module(‘ui.bootstrap.demo‘, [‘ui.bootstrap‘]).controller(‘PagerDemoCtrl‘, function ($scope) {            $scope.totalItems = 64;            $scope.currentPage = 4;        });    </script></head><body>    <div ng-controller="PagerDemoCtrl">        <h4>Pager</h4>        <uib-pager total-items="totalItems" ng-model="currentPage" next-text="下一頁" previous-text="上一頁" num-pages="totalPage"></uib-pager>        <pre>當前頁:{{currentPage}},總頁數:{{totalPage}}</pre> </div></body></html>

 

效果為:

 

Pager中可以使用的屬性有:

屬性名稱 預設值 備忘
align true 上一頁和下一頁的按鈕是否兩邊對齊
items-per-page 10 每頁顯示的數量.設定值小於1表示顯示所有項
next-text Next ? 下一頁的按鈕名稱
ng-disabled false 是否禁用
ng-model   當前第幾頁
num-pages angular.noop 唯讀屬性,表示總頁數
previous-text ? Previous 上一頁的按鈕名稱
template-url uib/template/pager/pager.html  
total-items   總共有多少條資料

在Pager控制項中,num-pages是唯讀屬性,由控制項根據total-items和items-per-page計算出總頁數。

 

這是Pagination的例子:

 

<!DOCTYPE html><html ng-app="ui.bootstrap.demo" xmlns="http://www.w3.org/1999/xhtml"><head>    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />    <link href="/Content/bootstrap.css" rel="stylesheet" />    <title></title>    <script src="/Scripts/angular.js"></script>    <script src="/Scripts/ui-bootstrap-tpls-1.3.2.js"></script>     <script>        angular.module(‘ui.bootstrap.demo‘, [‘ui.bootstrap‘]).controller(‘PaginationDemoCtrl‘, function ($scope) {            $scope.maxSize = 5;            $scope.totalItems = 175;            $scope.currentPage = 1;        });    </script></head><body>    <div ng-controller="PaginationDemoCtrl">        <uib-pagination total-items="totalItems" ng-model="currentPage" max-size="maxSize" first-text="第一頁" previous-text="上一頁" next-text="下一頁" last-text="最後頁" boundary-links="true" boundary-link-numbers="true"></uib-pagination>    </div></body></html>

 

效果為:

 Pagination中可以使用的屬性有:

屬性名稱 預設值 備忘
boundary-links false 是否顯示第一頁和最後一頁的按鈕
boundary-link-numbers false 是否顯示第一頁和最後一頁的頁數,並在頁數過多時用…表示被隱藏的頁數
direction-links true 是否顯示上一頁和下一頁的按鈕
first-text first 第一頁的按鈕的名字
last-text last 最後一頁的按鈕名字
previous-text Previous 上一頁的按鈕名字
next-text Next 下一頁的按鈕名字
force-ellipses false 是否在rotate被設定為true並且頁數過多時顯示為"…"
rotate true 是否保持當前在可視範圍的中間
items-per-page 10 每頁顯示的數量.設定值小於1表示顯示所有項
max-size null 可選擇的頁數範圍(如果設定為5,當前頁為10,總頁數為100,那麼可選擇第8,9,10,11,12頁)
ng-change   頁數變化時調用的函數
ng-disabled false 是否禁用
ng-model   當前頁數
num-pages angular.noop 唯讀屬性,表示總頁數
page-label angular.identity 設定頁數標籤的運算式
template-url uib/template/pagination/pagination.html  
total-items   總共有多少條資料

boundary-link-numbers,rotate和force-ellipses是用來控制頁數按鈕的顯示方式,並且可以組合使用。

page-label是一個很有用的屬性,可以設定一個運算式來改變頁數按鈕的文本,比如page-label="‘p‘+$page" 效果為:

 

AngularJs的UI組件ui-Bootstrap分享(五)——Pager和Pagination

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.