File tree Expand file tree Collapse file tree 4 files changed +15
-2
lines changed Expand file tree Collapse file tree 4 files changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -121,6 +121,8 @@ function DataTable<T>(props: TableProps<T>): JSX.Element {
121
121
onColumnOrderChange = defaultProps . onColumnOrderChange ,
122
122
keepExpandableFirst = defaultProps . keepExpandableFirst ,
123
123
footer = defaultProps . footer ,
124
+ currentSortColumnId = defaultProps . currentSortColumnId ,
125
+ currentSortDirection = defaultProps . currentSortDirection ,
124
126
} = props ;
125
127
126
128
const {
@@ -492,6 +494,8 @@ function DataTable<T>(props: TableProps<T>): JSX.Element {
492
494
onDragEnter = { handleDragEnter }
493
495
onDragLeave = { handleDragLeave }
494
496
draggingColumnId = { draggingColumnId }
497
+ currentSortColumnId = { currentSortColumnId }
498
+ currentSortDirection = { currentSortDirection }
495
499
/>
496
500
) ) }
497
501
</ HeadRow >
Original file line number Diff line number Diff line change @@ -98,6 +98,8 @@ type TableColProps<T> = {
98
98
onDragEnd : ( e : React . DragEvent < HTMLDivElement > ) => void ;
99
99
onDragEnter : ( e : React . DragEvent < HTMLDivElement > ) => void ;
100
100
onDragLeave : ( e : React . DragEvent < HTMLDivElement > ) => void ;
101
+ currentSortColumnId : string | number | null ;
102
+ currentSortDirection : SortOrder ;
101
103
} ;
102
104
103
105
function TableCol < T > ( {
@@ -118,6 +120,8 @@ function TableCol<T>({
118
120
onDragEnd,
119
121
onDragEnter,
120
122
onDragLeave,
123
+ currentSortColumnId,
124
+ currentSortDirection,
121
125
} : TableColProps < T > ) : JSX . Element | null {
122
126
React . useEffect ( ( ) => {
123
127
if ( typeof column . selector === 'string' ) {
@@ -168,14 +172,14 @@ function TableCol<T>({
168
172
} ;
169
173
170
174
const renderNativeSortIcon = ( sortActive : boolean ) => (
171
- < NativeSortIcon sortActive = { sortActive } sortDirection = { sortDirection } />
175
+ < NativeSortIcon sortActive = { sortActive } sortDirection = { currentSortDirection } />
172
176
) ;
173
177
174
178
const renderCustomSortIcon = ( ) => (
175
179
< span className = { [ sortDirection , '__rdt_custom_sort_icon__' ] . join ( ' ' ) } > { sortIcon } </ span >
176
180
) ;
177
181
178
- const sortActive = ! ! ( column . sortable && equalizeId ( selectedColumn . id , column . id ) ) ;
182
+ const sortActive = ! ! ( column . sortable && currentSortColumnId !== null && equalizeId ( currentSortColumnId , column . id ) ) ;
179
183
const disableSort = ! column . sortable || disabled ;
180
184
const nativeSortIconLeft = column . sortable && ! sortIcon && ! column . right ;
181
185
const nativeSortIconRight = column . sortable && ! sortIcon && column . right ;
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ import ExpanderCollapsedIcon from '../icons/ExpanderCollapsedIcon';
7
7
import ExpanderExpandedIcon from '../icons/ExpanderExpandedIcon' ;
8
8
import { noop } from './util' ;
9
9
import { Alignment , Direction } from './constants' ;
10
+ import { SortOrder } from './types' ;
10
11
11
12
export const defaultProps = {
12
13
columns : [ ] ,
@@ -108,4 +109,6 @@ export const defaultProps = {
108
109
onColumnOrderChange : noop ,
109
110
keepExpandableFirst : false ,
110
111
footer : null ,
112
+ currentSortColumnId : null ,
113
+ currentSortDirection : 'asc' as SortOrder ,
111
114
} ;
Original file line number Diff line number Diff line change @@ -118,6 +118,8 @@ export type TableProps<T> = {
118
118
* */
119
119
title ?: string | React . ReactNode ;
120
120
footer ?: React . ReactNode ;
121
+ currentSortColumnId : string | number | null ;
122
+ currentSortDirection : SortOrder ;
121
123
} ;
122
124
123
125
export type TableColumnBase = {
You can’t perform that action at this time.
0 commit comments