@@ -110,6 +110,7 @@ export default class ItemsTable extends React.Component {
110110 orderByField : PropTypes . string ,
111111 orderByReverse : PropTypes . bool ,
112112 toggleSorting : PropTypes . func ,
113+ setSorting : PropTypes . func ,
113114 "data-test" : PropTypes . string ,
114115 rowKey : PropTypes . oneOfType ( [ PropTypes . string , PropTypes . func ] ) ,
115116 } ;
@@ -127,7 +128,7 @@ export default class ItemsTable extends React.Component {
127128 } ;
128129
129130 prepareColumns ( ) {
130- const { orderByField, orderByReverse, toggleSorting } = this . props ;
131+ const { orderByField, orderByReverse } = this . props ;
131132 const orderByDirection = orderByReverse ? "descend" : "ascend" ;
132133
133134 return map (
@@ -136,17 +137,13 @@ export default class ItemsTable extends React.Component {
136137 column => extend ( column , { orderByField : column . orderByField || column . field } )
137138 ) ,
138139 ( column , index ) => {
139- // Bind click events only to sortable columns
140- const onHeaderCell = column . sorter ? ( ) => ( { onClick : ( ) => toggleSorting ( column . orderByField ) } ) : null ;
141-
142140 // Wrap render function to pass correct arguments
143141 const render = isFunction ( column . render ) ? ( text , row ) => column . render ( text , row . item ) : identity ;
144142
145143 return extend ( omit ( column , [ "field" , "orderByField" , "render" ] ) , {
146144 key : "column" + index ,
147145 dataIndex : [ "item" , column . field ] ,
148146 defaultSortOrder : column . orderByField === orderByField ? orderByDirection : null ,
149- onHeaderCell,
150147 render,
151148 } ) ;
152149 }
@@ -179,6 +176,27 @@ export default class ItemsTable extends React.Component {
179176 } )
180177 : null ;
181178
179+ const onChange = ( pagination , filters , sorter , extra ) => {
180+ const action = extra ?. action ;
181+ if ( action === "sort" ) {
182+ const propsColumn = this . props . columns . find ( column => column . field === sorter . field [ 1 ] ) ;
183+ if ( ! propsColumn . sorter ) {
184+ return ;
185+ }
186+ let orderByField = propsColumn . orderByField ;
187+ const orderByReverse = sorter . order === "descend" ;
188+
189+ if ( orderByReverse === undefined ) {
190+ orderByField = null ;
191+ }
192+ if ( this . props . setSorting ) {
193+ this . props . setSorting ( orderByField , orderByReverse ) ;
194+ } else {
195+ this . props . toggleSorting ( orderByField ) ;
196+ }
197+ }
198+ } ;
199+
182200 const { showHeader } = this . props ;
183201 if ( this . props . loading ) {
184202 if ( isEmpty ( tableDataProps . dataSource ) ) {
@@ -200,6 +218,7 @@ export default class ItemsTable extends React.Component {
200218 rowKey = { this . getRowKey }
201219 pagination = { false }
202220 onRow = { onTableRow }
221+ onChange = { onChange }
203222 data-test = { this . props [ "data-test" ] }
204223 { ...tableDataProps }
205224 />
0 commit comments