Skip to content

Commit

Permalink
fix(Table): fixed not working sorting when controlled sortState is used
Browse files Browse the repository at this point in the history
  • Loading branch information
zzzorgo committed Oct 4, 2023
1 parent 7568cdf commit 4c16983
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/components/Table/hoc/withTableSorting/withTableSorting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export interface WithTableSortingProps {
defaultSortState?: SortState;
sortState?: SortState;
onSortStateChange?: (sortState: SortState) => void;
disableDataSorting?: boolean;
}

interface WithTableSortingState {
Expand Down Expand Up @@ -73,10 +74,10 @@ export function withTableSorting<I extends TableDataItem, E extends {} = {}>(
}

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;
}

Expand Down Expand Up @@ -195,11 +196,13 @@ export function withTableSorting<I extends TableDataItem, E extends {} = {}>(
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() {
Expand Down

0 comments on commit 4c16983

Please sign in to comment.