@@ -25,6 +25,10 @@ import {
25
25
DATA_TABLE_COLUMN ,
26
26
} from '../../../utilities/constants' ;
27
27
28
+ const defaultProps = {
29
+ firstSortDirection : 'asc'
30
+ } ;
31
+
28
32
/**
29
33
* Used internally, renders each individual column heading.
30
34
*/
@@ -70,12 +74,18 @@ class DataTableHeaderCell extends React.Component {
70
74
* The current sort direction.
71
75
*/
72
76
sortDirection : PropTypes . oneOf ( [ 'desc' , 'asc' ] ) ,
77
+ /**
78
+ * The default sort direction for the first time if the column is not sorted and sortDirection not given
79
+ */
80
+ firstSortDirection : PropTypes . oneOf ( [ 'asc' , 'desc' ] ) ,
73
81
/**
74
82
* Width of column. This is required for advanced/fixed layout tables. Please provide units. (`rems` are recommended)
75
83
*/
76
84
width : PropTypes . string ,
77
85
} ;
78
86
87
+ static defaultProps = defaultProps ;
88
+
79
89
state = {
80
90
sortDirection : null ,
81
91
} ;
@@ -94,7 +104,11 @@ class DataTableHeaderCell extends React.Component {
94
104
handleSort = ( e ) => {
95
105
const oldSortDirection =
96
106
this . props . sortDirection || this . state . sortDirection ;
97
- const sortDirection = oldSortDirection === 'asc' ? 'desc' : 'asc' ;
107
+ // var sortDirection = this.props.firstSortDirection
108
+ // if (oldSortDirection) {
109
+ // sortDirection = oldSortDirection === 'asc' ? 'desc' : 'asc'
110
+ // }
111
+ const sortDirection = oldSortDirection ? ( oldSortDirection === 'asc' ? 'desc' : 'asc' ) : ( this . props . firstSortDirection )
98
112
const data = {
99
113
property : this . props . property ,
100
114
sortDirection,
@@ -114,7 +128,7 @@ class DataTableHeaderCell extends React.Component {
114
128
const { fixedHeader, isSorted, label, sortable, width } = this . props ;
115
129
116
130
const labelType = typeof label ;
117
- const sortDirection = this . props . sortDirection || this . state . sortDirection ;
131
+ const sortDirection = ( ! this . props . sortDirection && ! this . state . sortDirection ) ? this . props . firstSortDirection : ( this . props . sortDirection || this . state . sortDirection ) ;
118
132
const expandedSortDirection =
119
133
sortDirection === 'desc' ? 'descending' : 'ascending' ;
120
134
const ariaSort = isSorted ? expandedSortDirection : 'none' ;
@@ -144,7 +158,7 @@ class DataTableHeaderCell extends React.Component {
144
158
name = { sortDirection === 'desc' ? 'arrowdown' : 'arrowup' }
145
159
size = "x-small"
146
160
/>
147
- { sortDirection ? (
161
+ { ( sortDirection && this . state . sortable ) ? (
148
162
< span
149
163
className = "slds-assistive-text"
150
164
aria-live = "assertive"
0 commit comments