Merge pull request #337 from mailpoet/fix_listing_pagination
Pagination issues
This commit is contained in:
@@ -7,7 +7,11 @@ define(['react', 'classnames'], function(React, classNames) {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
setPage: function(page) {
|
setPage: function(page) {
|
||||||
this.props.onSetPage(page);
|
this.setState({
|
||||||
|
page: null
|
||||||
|
}, function () {
|
||||||
|
this.props.onSetPage(this.constrainPage(page));
|
||||||
|
}.bind(this));
|
||||||
},
|
},
|
||||||
setFirstPage: function() {
|
setFirstPage: function() {
|
||||||
this.setPage(1);
|
this.setPage(1);
|
||||||
@@ -16,10 +20,14 @@ define(['react', 'classnames'], function(React, classNames) {
|
|||||||
this.setPage(this.getLastPage());
|
this.setPage(this.getLastPage());
|
||||||
},
|
},
|
||||||
setPreviousPage: function() {
|
setPreviousPage: function() {
|
||||||
this.setPage(this.constrainPage(this.props.page - 1));
|
this.setPage(this.constrainPage(
|
||||||
|
parseInt(this.props.page, 10) - 1)
|
||||||
|
);
|
||||||
},
|
},
|
||||||
setNextPage: function() {
|
setNextPage: function() {
|
||||||
this.setPage(this.constrainPage(this.props.page + 1));
|
this.setPage(this.constrainPage(
|
||||||
|
parseInt(this.props.page, 10) + 1)
|
||||||
|
);
|
||||||
},
|
},
|
||||||
constrainPage: function(page) {
|
constrainPage: function(page) {
|
||||||
return Math.min(Math.max(1, Math.abs(~~page)), this.getLastPage());
|
return Math.min(Math.max(1, Math.abs(~~page)), this.getLastPage());
|
||||||
@@ -27,14 +35,16 @@ define(['react', 'classnames'], function(React, classNames) {
|
|||||||
handleSetManualPage: function(e) {
|
handleSetManualPage: function(e) {
|
||||||
if(e.which === 13) {
|
if(e.which === 13) {
|
||||||
this.setPage(this.state.page);
|
this.setPage(this.state.page);
|
||||||
this.setState({ page: null });
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
handleChangeManualPage: function(e) {
|
handleChangeManualPage: function(e) {
|
||||||
this.setState({
|
this.setState({
|
||||||
page: this.constrainPage(e.target.value)
|
page: e.target.value
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
handleBlurManualPage: function(e) {
|
||||||
|
this.setPage(e.target.value);
|
||||||
|
},
|
||||||
getLastPage: function() {
|
getLastPage: function() {
|
||||||
return Math.ceil(this.props.count / this.props.limit);
|
return Math.ceil(this.props.count / this.props.limit);
|
||||||
},
|
},
|
||||||
@@ -101,6 +111,11 @@ define(['react', 'classnames'], function(React, classNames) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let pageValue = this.props.page;
|
||||||
|
if(this.state.page !== null) {
|
||||||
|
pageValue = this.state.page;
|
||||||
|
}
|
||||||
|
|
||||||
pagination = (
|
pagination = (
|
||||||
<span className="pagination-links">
|
<span className="pagination-links">
|
||||||
{firstPage}
|
{firstPage}
|
||||||
@@ -115,10 +130,11 @@ define(['react', 'classnames'], function(React, classNames) {
|
|||||||
type="text"
|
type="text"
|
||||||
onChange={ this.handleChangeManualPage }
|
onChange={ this.handleChangeManualPage }
|
||||||
onKeyUp={ this.handleSetManualPage }
|
onKeyUp={ this.handleSetManualPage }
|
||||||
|
onBlur={ this.handleBlurManualPage }
|
||||||
aria-describedby="table-paging"
|
aria-describedby="table-paging"
|
||||||
size="1"
|
size="1"
|
||||||
ref="page"
|
ref="page"
|
||||||
value={ this.state.page || this.props.page }
|
value={ pageValue }
|
||||||
name="paged"
|
name="paged"
|
||||||
id="current-page-selector"
|
id="current-page-selector"
|
||||||
className="current-page" />
|
className="current-page" />
|
||||||
|
Reference in New Issue
Block a user