From a741242fdb061c94ee053d04ed7706ca2e4ef87f Mon Sep 17 00:00:00 2001 From: Ravgeet Dhillon Date: Mon, 24 Jul 2023 18:40:03 +0530 Subject: [PATCH] fix: made currentSortColumnId and currentSortDirection optional --- src/DataTable/TableCol.tsx | 13 +++++++++---- src/DataTable/defaultProps.tsx | 4 ++-- src/DataTable/types.ts | 4 ++-- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/DataTable/TableCol.tsx b/src/DataTable/TableCol.tsx index 8e239671..4ae30032 100644 --- a/src/DataTable/TableCol.tsx +++ b/src/DataTable/TableCol.tsx @@ -98,8 +98,8 @@ type TableColProps = { onDragEnd: (e: React.DragEvent) => void; onDragEnter: (e: React.DragEvent) => void; onDragLeave: (e: React.DragEvent) => void; - currentSortColumnId: string | number | null; - currentSortDirection: SortOrder; + currentSortColumnId?: string | number | null; + currentSortDirection?: SortOrder; }; function TableCol({ @@ -172,14 +172,19 @@ function TableCol({ }; const renderNativeSortIcon = (sortActive: boolean) => ( - + ); const renderCustomSortIcon = () => ( {sortIcon} ); - const sortActive = !!(column.sortable && currentSortColumnId !== null && equalizeId(currentSortColumnId, column.id)); + const sortActive = (() => { + if (currentSortColumnId !== null) { + return !!(column.sortable && equalizeId(currentSortColumnId, column.id)); + } + return !!(column.sortable && equalizeId(selectedColumn.id, column.id)); + })(); const disableSort = !column.sortable || disabled; const nativeSortIconLeft = column.sortable && !sortIcon && !column.right; const nativeSortIconRight = column.sortable && !sortIcon && column.right; diff --git a/src/DataTable/defaultProps.tsx b/src/DataTable/defaultProps.tsx index aec179a9..6f325052 100644 --- a/src/DataTable/defaultProps.tsx +++ b/src/DataTable/defaultProps.tsx @@ -7,7 +7,7 @@ import ExpanderCollapsedIcon from '../icons/ExpanderCollapsedIcon'; import ExpanderExpandedIcon from '../icons/ExpanderExpandedIcon'; import { noop } from './util'; import { Alignment, Direction } from './constants'; -import { SortOrder } from './types'; +// import { SortOrder } from './types'; export const defaultProps = { columns: [], @@ -110,5 +110,5 @@ export const defaultProps = { keepExpandableFirst: false, footer: null, currentSortColumnId: null, - currentSortDirection: 'asc' as SortOrder, + currentSortDirection: undefined, }; diff --git a/src/DataTable/types.ts b/src/DataTable/types.ts index c123811e..9c03b98c 100644 --- a/src/DataTable/types.ts +++ b/src/DataTable/types.ts @@ -118,8 +118,8 @@ export type TableProps = { * */ title?: string | React.ReactNode; footer?: React.ReactNode; - currentSortColumnId: string | number | null; - currentSortDirection: SortOrder; + currentSortColumnId?: string | number | null; + currentSortDirection?: SortOrder; }; export type TableColumnBase = {