Skip to content

Commit

Permalink
Add sortDefaults to datatable to fix initial useEffect reseting sort (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
dgading authored Jun 24, 2022
1 parent e51a73d commit 45bd37c
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/components/DataTable/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const DataTable = ({
loading,
options,
columnDefaults,
sortDefaults,
setSort,
setConditions,
conditionsTransform,
Expand Down Expand Up @@ -122,7 +123,9 @@ const DataTable = ({
columns,
data,
filterTypes,
initialState: {},
initialState: {
sortBy: sortDefaults
},
manualPagination: true,
manualFilters: true,
manualSortBy: true,
Expand All @@ -136,7 +139,6 @@ const DataTable = ({
usePagination,
layout === "block" ? useBlockLayout : useFlexLayout
);

useEffect(() => {
if (columnSort) {
const normalizedSort = sortTransform ? sortTransform(sortBy) : filters;
Expand Down Expand Up @@ -317,6 +319,7 @@ DataTable.propTypes = {
columnSort: PropTypes.bool,
columnResize: PropTypes.bool,
}),
sortDefaults: [],
columns: PropTypes.arrayOf(
PropTypes.shape({
Header: PropTypes.string.isRequired,
Expand Down

0 comments on commit 45bd37c

Please sign in to comment.