Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/panthershark/pager-model
Generates a pagination model for binding into templates
https://github.com/panthershark/pager-model
Last synced: about 2 months ago
JSON representation
Generates a pagination model for binding into templates
- Host: GitHub
- URL: https://github.com/panthershark/pager-model
- Owner: panthershark
- License: mit
- Created: 2014-06-10T20:15:55.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2014-07-25T21:41:50.000Z (over 10 years ago)
- Last Synced: 2024-04-15T14:27:04.503Z (9 months ago)
- Language: JavaScript
- Size: 180 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
pager-model
===========Generates a pagination model for binding into templates
# Usage
Pass the params from your results to generate a view model that is ready to bind to your templates.
### Arguments
* **start**: Index of the first item
* **total**: Total number of results
* **size**: page size
* **range**: number of pages to generate (for links between prev & next)
* **url**: function for generating a url from the pagenumber.
* **vm**: function for generating a view model for injecting other about the page.### Example
```javascript
var pager = require('pager-model');
var model = pager.pagination({
start: 52,
total: 95,
size: 10,
range: 4,// allows DI for url generation
url: function(page_number, page_size) {
return '/items/' + page_number + '?limit=' + page_size;
},// helpful for generating models to plug into your existing templates.
vm: function(page_number, page_size) {
return {
type: 'item',
num: page_number,
size: page_size
}
}
});console.log(JSON.stringify(model));
```
### Output
```javascript
{
"current_page": 6,
"next": {
"selected": false,
"url": "/items/7?limit=10",
"vm": {
"num": 7,
"size": 10,
"type": "item"
}
},
"page_count": 10,
"page_size": 10,
"pages": [
{
"selected": false,
"url": "/items/4?limit=10",
"vm": {
"num": 4,
"size": 10,
"type": "item"
}
},
{
"selected": false,
"url": "/items/5?limit=10",
"vm": {
"num": 5,
"size": 10,
"type": "item"
}
},
{
"selected": true,
"url": "/items/6?limit=10",
"vm": {
"num": 6,
"size": 10,
"type": "item"
}
},
{
"selected": false,
"url": "/items/7?limit=10",
"vm": {
"num": 7,
"size": 10,
"type": "item"
}
},
{
"selected": false,
"url": "/items/8?limit=10",
"vm": {
"num": 8,
"size": 10,
"type": "item"
}
}
],
"previous": {
"selected": false,
"url": "/items/5?limit=10",
"vm": {
"num": 5,
"size": 10,
"type": "item"
}
},
"total": 95
}
```