Skip to content

Commit 7e558ce

Browse files
author
vvo
committed
feat(pagination): add hitsPerPage and maxPages options
1 parent fad2720 commit 7e558ce

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ npm run test:coverage
9797
// cssClass: 'pagination', // no default
9898
// padding: 3, // number of page numbers to show before/after current
9999
// showFirstLast: true, // show or hide first and last links
100+
// hitsPerPage: 20,
101+
// maxPages, // automatically computed based on the result set
100102
// labels: {
101103
// previous: '‹', // ‹
102104
// next: '›', // ›

example/app.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ instant.addWidget(
2929
instant.addWidget(
3030
instantsearch.widgets.pagination({
3131
container: '#pagination',
32-
cssClass: 'pagination'
32+
cssClass: 'pagination',
33+
hitsPerPage: 5,
34+
maxPages: 20
3335
})
3436
);
3537

widgets/pagination/index.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,27 @@ var React = require('react');
44

55
var utils = require('../../lib/widgetUtils.js');
66

7-
function hits(params) {
7+
function hits({container, cssClass, labels, hitsPerPage=20, maxPages}={}) {
88
var Pagination = require('../../components/Pagination/');
9-
var containerNode = utils.getContainerNode(params.container);
9+
var containerNode = utils.getContainerNode(container);
1010

1111
return {
12+
getConfiguration: function() {
13+
return {
14+
hitsPerPage
15+
};
16+
},
1217
render: function(results, state, helper) {
18+
var nbPages = maxPages !== undefined ? maxPages : results.nbPages;
19+
1320
React.render(
1421
<Pagination
1522
nbHits={results.nbHits}
1623
currentPage={results.page}
17-
nbPages={results.nbPages}
24+
nbPages={nbPages}
1825
setCurrentPage={helper.setCurrentPage.bind(helper)}
19-
cssClass={params.cssClass}
20-
labels={params.labels} />,
26+
cssClass={cssClass}
27+
labels={labels} />,
2128
containerNode
2229
);
2330
}

0 commit comments

Comments
 (0)