Skip to content

Commit

Permalink
Fix #2514: Fix sortFunction ignored on initial sort (#3060)
Browse files Browse the repository at this point in the history
* Fix #2514: If sortField is specified, determine and set columnSortable and columnSortFunction refs when processing data.  Otherwise, the refs are false and undefined, which results in the sortFunction not being run initially.

* Update var to const.
  • Loading branch information
emilytoy authored Jul 13, 2022
1 parent 1de8ad5 commit 2718dae
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions components/lib/datatable/DataTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -1236,6 +1236,13 @@ export const DataTable = React.forwardRef((props, ref) => {
const sortField = (localState && localState.sortField) || getSortField();
const sortOrder = (localState && localState.sortOrder) || getSortOrder();
const multiSortMeta = (localState && localState.multiSortMeta) || getMultiSortMeta();
const columns = getColumns();
const sortColumn = columns.find((col) => col.props.field === sortField);

if (sortColumn) {
columnSortable.current = sortColumn.props.sortable;
columnSortFunction.current = sortColumn.props.sortFunction;
}

if (ObjectUtils.isNotEmpty(filters) || props.globalFilter) {
data = filterLocal(data, filters);
Expand Down

0 comments on commit 2718dae

Please sign in to comment.