https://github.com/hackash/angular-hk-pager
A simple lightweight pagination module for angular js 1.*.*
https://github.com/hackash/angular-hk-pager
angularjs async module pagination
Last synced: 9 months ago
JSON representation
A simple lightweight pagination module for angular js 1.*.*
- Host: GitHub
- URL: https://github.com/hackash/angular-hk-pager
- Owner: hackash
- License: mit
- Created: 2016-12-17T21:21:37.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-01-21T18:03:43.000Z (over 9 years ago)
- Last Synced: 2025-10-12T15:18:28.492Z (10 months ago)
- Topics: angularjs, async, module, pagination
- Language: JavaScript
- Homepage:
- Size: 15.6 KB
- Stars: 4
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# angular-hk-pager
> A simple lightweight pagination module for angular js
[](https://travis-ci.org/hackash/angular-hk-pager)
## Installation
Add angular-hk-pager to your project:
```
bower install --save angular-hk-pager
```
Add it to your HTML file
```html
```
Reference it as a dependency for your app module:
```js
angular.module('myApp', ['hk.pager']);
```
### Requirements
This module requires:
* Angular.JS only
## Usage (default) static data
Create an instance of Pagination constructor function
```
var pagerParams = {
perPage: 10,
total: $scope.posts.length, // entire data length
page: 1
};
```
```
$scope.pagination = new Pagination(pagerParams).init();
```
Use the `hk-pager` directive to show a pagination controls:
```html
```
## Usage (async) dynamic data
Create an instance of Pagination constructor function, by passing mode flag with the value of `async`
```
var pagerParams = {
perPage: 10,
page: 1
};
```
```
$scope.pagination = new Pagination(pagerParams, 'async').init();
```
Create a wrapper function, which gets data by requesting to server
```
$scope.getData = function (params, done) {
done = angular.isFunction(done) ? done : angular.noop;
Data.getData(params).then(function (data) {
$scope.posts = data.posts;
if (!$scope.pagination.initialized) {
$scope.pagination.total = data.total;
$scope.pagination.init();
}
done();
});
}
```
Set async handler (function that will be invoked by Pagination function)
```
$scope.pagination.setAsyncHandler($scope.getData);
```
Now every time when you click on next, prev or page buttons,
`$scope.getData` function will be invoked with the following arguments
### params (object)
```
{
offset: $scope.pagination.offset,
perPage: $scope.pagination.perPage
}
```
### done (function)
must be called after resolving the promise
Use the `hk-pager` directive to show a pagination controls:
```html
```
## methods
`pagination.next(page)`
* navigates to next page if page param was not passed in and if has next
* navigates to specified page if page number is in range
`pagination.previous()`
* navigates to previous page if has previous
`pagination.init()`
* initializes pagination object
`pagination.hasNext()`
* returns `true` whether pagination has next page, otherwise `false`
`pagination.hasPrevious()`
* returns `true` whether pagination has previous page, otherwise `false`
`pagination.setAsyncHandler()`
* sets async handler (available only when `pagination.mode` is set to `async`)
### examples
* [async](example/async-paging.html)
* [default](example/default-paging.html)
### License
```
Copyright (C) 2015-2016 by Ashot Harutyunyan
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
```