1
+ import '@ui5/webcomponents-icons/dist/icons/decline' ;
1
2
import { enrichEventWithDetails } from '@ui5/webcomponents-react-base/lib/Utils' ;
2
3
import { CustomListItem } from '@ui5/webcomponents-react/lib/CustomListItem' ;
3
4
import { FlexBox } from '@ui5/webcomponents-react/lib/FlexBox' ;
@@ -20,13 +21,13 @@ export interface ColumnHeaderModalProperties {
20
21
showGroup ?: boolean ;
21
22
column : ColumnType ;
22
23
style : CSSProperties ;
23
- onSort ?: ( e : CustomEvent < { column : unknown ; sortDirection : string } > ) => void ;
24
- onGroupBy ?: ( e : CustomEvent < { column : unknown ; isGrouped : boolean } > ) => void ;
24
+ onSort ?: ( e : CustomEvent < { column : unknown ; sortDirection : string } > ) => void ;
25
+ onGroupBy ?: ( e : CustomEvent < { column : unknown ; isGrouped : boolean } > ) => void ;
25
26
}
26
27
27
28
const staticStyle = { fontWeight : 'normal' } ;
28
29
29
- export const ColumnHeaderModal : FC < ColumnHeaderModalProperties > = ( props ) => {
30
+ export const ColumnHeaderModal : FC < ColumnHeaderModalProperties > = ( props : ColumnHeaderModalProperties ) => {
30
31
const { showGroup, showSort, showFilter, column, style, openBy, onSort, onGroupBy } = props ;
31
32
32
33
const { Filter } = column ;
@@ -60,6 +61,17 @@ export const ColumnHeaderModal: FC<ColumnHeaderModalProperties> = (props) => {
60
61
) ;
61
62
}
62
63
break ;
64
+ case 'clear' :
65
+ column . clearSortBy ( ) ;
66
+ if ( typeof onSort === 'function' ) {
67
+ onSort (
68
+ enrichEventWithDetails ( e , {
69
+ column,
70
+ sortDirection : sortType
71
+ } )
72
+ ) ;
73
+ }
74
+ break ;
63
75
case 'group' :
64
76
const willGroup = ! column . isGrouped ;
65
77
column . toggleGroupBy ( willGroup ) ;
@@ -77,9 +89,12 @@ export const ColumnHeaderModal: FC<ColumnHeaderModalProperties> = (props) => {
77
89
popoverRef . current . close ( ) ;
78
90
}
79
91
} ,
80
- [ column , popoverRef , onGroupBy ]
92
+ [ column , popoverRef , onGroupBy , onSort ]
81
93
) ;
82
94
95
+ const isSortedAscending = column . isSorted && column . isSortedDesc === false ;
96
+ const isSortedDescending = column . isSorted && column . isSortedDesc === true ;
97
+
83
98
return (
84
99
< Popover
85
100
openByStyle = { style }
@@ -91,16 +106,26 @@ export const ColumnHeaderModal: FC<ColumnHeaderModalProperties> = (props) => {
91
106
style = { staticStyle as CSSProperties }
92
107
>
93
108
< List onItemClick = { handleSort } >
94
- { showSort && (
95
- < StandardListItem type = { ListItemTypes . Active } icon = { 'sort-ascending' } data-sort = { 'asc' } >
109
+ { isSortedAscending && (
110
+ < StandardListItem type = { ListItemTypes . Active } icon = "decline" data-sort = "clear" >
111
+ Clear Sorting
112
+ </ StandardListItem >
113
+ ) }
114
+ { showSort && ! isSortedAscending && (
115
+ < StandardListItem type = { ListItemTypes . Active } icon = "sort-ascending" data-sort = "asc" >
96
116
Sort Ascending
97
117
</ StandardListItem >
98
118
) }
99
- { showSort && (
100
- < StandardListItem type = { ListItemTypes . Active } icon = { ' sort-descending' } data-sort = { ' desc' } >
119
+ { showSort && ! isSortedDescending && (
120
+ < StandardListItem type = { ListItemTypes . Active } icon = " sort-descending" data-sort = " desc" >
101
121
Sort Descending
102
122
</ StandardListItem >
103
123
) }
124
+ { isSortedDescending && (
125
+ < StandardListItem type = { ListItemTypes . Active } icon = "decline" data-sort = "clear" >
126
+ Clear Sorting
127
+ </ StandardListItem >
128
+ ) }
104
129
{ showFilter && ! column . isGrouped && (
105
130
< CustomListItem type = { ListItemTypes . Inactive } >
106
131
< FlexBox alignItems = { FlexBoxAlignItems . Center } style = { { padding : '0px 1rem' } } >
0 commit comments