├── .gitignore
├── LICENSE.txt
├── README.md
├── bower.json
├── karma.conf.js
├── package.json
├── simplePagination.js
└── simplePagination.spec.js
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | .DS_Store
3 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | Copyright (c) 2014 Svilen Gospodinov
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining
4 | a copy of this software and associated documentation files (the
5 | "Software"), to deal in the Software without restriction, including
6 | without limitation the rights to use, copy, modify, merge, publish,
7 | distribute, sublicense, and/or sell copies of the Software, and to
8 | permit persons to whom the Software is furnished to do so, subject to
9 | the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be
12 | included in all copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ng-simplePagination
2 |
3 | **Previously known as "angular-SimplePagination"**; is an AngularJS module for simple pagination on static data. No directives here, just a service and some helpful filters.
4 |
5 | Mostly based on various snippets which I found on JSFiddle, with some changes by me.
6 |
7 | ## Quick start
8 |
9 | ```bash
10 | bower install ng-simplePagination
11 | ```
12 | or alternatively download and include `simplePagination.js` after `angular.min.js`.
13 |
14 | Add the `simplePagination` module as a dependency when creating your app, e.g.
15 |
16 | ```js
17 | var app = angular.module('myApp', ['simplePagination']);`
18 | ```
19 |
20 | Inject the `Pagination` service to the controller containing the data which you want to paginate, and set it on the $scope:
21 |
22 | ```js
23 | app.controller('MyCtrl', ['$scope', 'Pagination',
24 | function($scope, Pagination) {
25 | $scope.pagination = Pagination.getNew();
26 | }]);
27 | ```
28 |
29 | This defaults to 5 items per page. You can pass an optional parameter with the number of items you want per page:
30 |
31 | ```js
32 | $scope.pagination = Pagination.getNew(10);
33 | ```
34 |
35 | Finally, calculate and set the number of pages depending on your data. Here's an example with a pre-defined `$scope.posts` array for a blog application:
36 |
37 | ```js
38 | $scope.pagination.numPages = Math.ceil($scope.posts.length/$scope.pagination.perPage);
39 | ```
40 |
41 | Replace `$scope.posts` with whatever data you have initialised.
42 |
43 | ## Rendering
44 |
45 | There is a custom filter called `startFrom` to help you rendering items per page.
46 |
47 | ```html
48 |
49 |
50 |
51 | ```
52 |
53 | Again, replace `post in posts` with your data.
54 |
55 | ### Previous / Next page buttons
56 | ```html
57 |
58 |
59 | ```
60 | Optionally you can add some logic to hide/disable the buttons using the `pagination.page` and `pagination.numPages` attributes; here's an example:
61 |
62 | ```html
63 | ng-hide="pagination.page == 0" ng-click="pagination.prevPage()"
64 | ng-hide="pagination.page + 1 >= pagination.numPages" ng-click="pagination.nextPage()"
65 | ```
66 |
67 | ### Page numbers
68 | Using another built-in filter called `range`:
69 | ```html
70 |