Skip to content

Commit

Permalink
Merge pull request #105 from langleyfoxall/feature/on-error
Browse files Browse the repository at this point in the history
Allow errors in AJAX requests issued by the AjaxDynamicDataTable to be captured
  • Loading branch information
Jordan Hall authored Sep 11, 2020
2 parents 48b5685 + 63f3a02 commit 8be208e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
11 changes: 11 additions & 0 deletions dist/AjaxDynamicDataTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ var AjaxDynamicDataTable = /*#__PURE__*/function (_Component) {
orderByDirection = _this$state2.orderByDirection;
var _this$props2 = this.props,
onLoad = _this$props2.onLoad,
onError = _this$props2.onError,
params = _this$props2.params,
axios = _this$props2.axios;
this.setState({
Expand Down Expand Up @@ -263,6 +264,12 @@ var AjaxDynamicDataTable = /*#__PURE__*/function (_Component) {
_this2.setState(newState);

onLoad(newState);
})["catch"](function (e) {
_this2.setState({
loading: false
});

onError(e);
});
});
}
Expand Down Expand Up @@ -313,6 +320,9 @@ AjaxDynamicDataTable.defaultProps = {
onLoad: function onLoad() {
return null;
},
onError: function onError() {
return null;
},
loading: false,
params: {},
defaultOrderByField: null,
Expand All @@ -324,6 +334,7 @@ AjaxDynamicDataTable.defaultProps = {
AjaxDynamicDataTable.propTypes = {
apiUrl: _propTypes["default"].string,
onLoad: _propTypes["default"].func,
onError: _propTypes["default"].func,
loading: _propTypes["default"].bool,
params: _propTypes["default"].object,
defaultOrderByField: _propTypes["default"].string,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@langleyfoxall/react-dynamic-data-table",
"version": "7.16.0",
"version": "7.17.0",
"description": "Re-usable data table for React with sortable columns, pagination and more.",
"keywords": [
"react",
Expand Down
10 changes: 9 additions & 1 deletion src/AjaxDynamicDataTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class AjaxDynamicDataTable extends Component {

loadPage(page) {
const {perPage, orderByField, orderByDirection} = this.state;
const {onLoad, params, axios} = this.props;
const {onLoad, onError, params, axios} = this.props;

this.setState(
{ loading: true },
Expand Down Expand Up @@ -131,6 +131,12 @@ class AjaxDynamicDataTable extends Component {

this.setState(newState);
onLoad(newState);

}).catch((e) => {

this.setState({ loading: false });
onError(e);

});
}
);
Expand Down Expand Up @@ -159,6 +165,7 @@ class AjaxDynamicDataTable extends Component {

AjaxDynamicDataTable.defaultProps = {
onLoad: () => null,
onError: () => null,
loading: false,
params: {},
defaultOrderByField: null,
Expand All @@ -172,6 +179,7 @@ AjaxDynamicDataTable.defaultProps = {
AjaxDynamicDataTable.propTypes = {
apiUrl: PropTypes.string,
onLoad: PropTypes.func,
onError: PropTypes.func,
loading: PropTypes.bool,
params: PropTypes.object,
defaultOrderByField: PropTypes.string,
Expand Down

0 comments on commit 8be208e

Please sign in to comment.