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

Commit add330c

Browse files
authored
Merge pull request #78 from Hyperkid123/custom-table-sort
Allow custom sorting on generic table.
2 parents 804eba3 + 009d3d5 commit add330c

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/table/genericPreviewTable.jsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,13 @@ class GenericPreviewTable extends Component {
134134

135135
sortColumn = property => this.setState((prevState) => {
136136
const asc = prevState.sortableColumnPropery === property ? !prevState.sortOrderAsc : true;
137+
if (this.props.customSort) {
138+
this.props.customSort(property);
139+
}
137140
return {
138141
sortableColumnPropery: property,
139142
sortOrderAsc: asc,
140-
rows: prevState.rows.sort((a, b) => (asc ? a[property] > b[property] : a[property] < b[property])),
143+
rows: this.props.customSort ? prevState.rows : prevState.rows.sort((a, b) => (asc ? a[property] > b[property] : a[property] < b[property])),
141144
};
142145
})
143146

@@ -212,6 +215,7 @@ GenericPreviewTable.propTypes = {
212215
showIcon: PropTypes.bool,
213216
icon: tableIconProp,
214217
rowKey: PropTypes.string,
218+
customSort: PropTypes.func,
215219
};
216220

217221
GenericPreviewTable.defaultProps = {

0 commit comments

Comments
 (0)