Skip to content
This repository has been archived by the owner on Aug 25, 2021. It is now read-only.

Commit

Permalink
Merge pull request #78 from Hyperkid123/custom-table-sort
Browse files Browse the repository at this point in the history
Allow custom sorting on generic table.
  • Loading branch information
karelhala authored Sep 19, 2018
2 parents 804eba3 + 009d3d5 commit add330c
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/table/genericPreviewTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,13 @@ class GenericPreviewTable extends Component {

sortColumn = property => this.setState((prevState) => {
const asc = prevState.sortableColumnPropery === property ? !prevState.sortOrderAsc : true;
if (this.props.customSort) {
this.props.customSort(property);
}
return {
sortableColumnPropery: property,
sortOrderAsc: asc,
rows: prevState.rows.sort((a, b) => (asc ? a[property] > b[property] : a[property] < b[property])),
rows: this.props.customSort ? prevState.rows : prevState.rows.sort((a, b) => (asc ? a[property] > b[property] : a[property] < b[property])),
};
})

Expand Down Expand Up @@ -212,6 +215,7 @@ GenericPreviewTable.propTypes = {
showIcon: PropTypes.bool,
icon: tableIconProp,
rowKey: PropTypes.string,
customSort: PropTypes.func,
};

GenericPreviewTable.defaultProps = {
Expand Down

0 comments on commit add330c

Please sign in to comment.