diff --git a/src/components/Table/hoc/withTableSorting/withTableSorting.tsx b/src/components/Table/hoc/withTableSorting/withTableSorting.tsx index 8a287bd97f..994fd13b09 100644 --- a/src/components/Table/hoc/withTableSorting/withTableSorting.tsx +++ b/src/components/Table/hoc/withTableSorting/withTableSorting.tsx @@ -28,6 +28,7 @@ export interface WithTableSortingProps { defaultSortState?: SortState; sortState?: SortState; onSortStateChange?: (sortState: SortState) => void; + disableDataSorting?: boolean; } interface WithTableSortingState { @@ -73,10 +74,10 @@ export function withTableSorting( } private getSortedData() { - const {data, columns} = this.props; + const {data, columns, disableDataSorting = this.isControlledState()} = this.props; const sortState = this.getSortState(); - if (this.isControlledState() || sortState.length === 0) { + if (disableDataSorting || sortState.length === 0) { return data; } @@ -195,11 +196,13 @@ export function withTableSorting( private handleSortStateChange(newSortState: SortState) { const {onSortStateChange} = this.props; - if (this.isControlledState()) { - onSortStateChange!(newSortState); - } else { + if (!this.isControlledState()) { this.setState({sort: newSortState}); } + + if (onSortStateChange) { + onSortStateChange(newSortState); + } } private isControlledState() {