@@ -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,10 @@ 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
+ }
98
111
const data = {
99
112
property : this . props . property ,
100
113
sortDirection,
@@ -114,7 +127,7 @@ class DataTableHeaderCell extends React.Component {
114
127
const { fixedHeader, isSorted, label, sortable, width } = this . props ;
115
128
116
129
const labelType = typeof label ;
117
- const sortDirection = this . props . sortDirection || this . state . sortDirection ;
130
+ const sortDirection = ( ! this . props . sortDirection && ! this . state . sortDirection ) ? this . props . firstSortDirection : ( this . props . sortDirection || this . state . sortDirection ) ;
118
131
const expandedSortDirection =
119
132
sortDirection === 'desc' ? 'descending' : 'ascending' ;
120
133
const ariaSort = isSorted ? expandedSortDirection : 'none' ;
@@ -144,7 +157,7 @@ class DataTableHeaderCell extends React.Component {
144
157
name = { sortDirection === 'desc' ? 'arrowdown' : 'arrowup' }
145
158
size = "x-small"
146
159
/>
147
- { sortDirection ? (
160
+ { ( sortDirection && this . state . sortable ) ? (
148
161
< span
149
162
className = "slds-assistive-text"
150
163
aria-live = "assertive"
0 commit comments