@@ -14,7 +14,7 @@ angular.module('patternfly.table').component('pfTableView', {
14
14
templateUrl : 'table/tableview/table-view.html' ,
15
15
controller : function ( DTOptionsBuilder , DTColumnDefBuilder , $element , pfUtils , $log , $filter , $timeout , $sce ) {
16
16
'use strict' ;
17
- var ctrl = this , prevDtOptions , prevItems , prevPageConfig ;
17
+ var ctrl = this , prevDtOptions , prevItems , prevPageConfig , prevShowCheckboxes ;
18
18
19
19
// Once datatables is out of active development I'll remove log statements
20
20
ctrl . debug = false ;
@@ -25,7 +25,7 @@ angular.module('patternfly.table').component('pfTableView', {
25
25
ctrl . defaultDtOptions = {
26
26
autoWidth : false ,
27
27
destroy : true ,
28
- order : [ [ 1 , "asc" ] ] ,
28
+ order : [ [ 0 , "asc" ] ] , //default to 1st (col 0) for sorting, updateConfigOptions() will adjust based on showCheckboxes
29
29
dom : "t" ,
30
30
paging : false ,
31
31
select : {
@@ -117,20 +117,23 @@ angular.module('patternfly.table').component('pfTableView', {
117
117
ctrl . dtOptions . displayLength = Number ( ctrl . dtOptions . displayLength ) ;
118
118
}
119
119
120
+ _ . defaults ( ctrl . dtOptions , ctrl . defaultDtOptions ) ;
121
+ _ . defaults ( ctrl . config , ctrl . defaultConfig ) ;
122
+
123
+ if ( ctrl . config . showCheckboxes !== prevShowCheckboxes ) {
124
+ // adjust column numbers based on whether or not there is a checkbox column
125
+ // multi-col order may be used. Ex: [[ 0, 'asc' ], [ 1, 'desc' ]]
126
+ _ . each ( ctrl . dtOptions . order , function ( col ) {
127
+ col [ 0 ] = ctrl . config . showCheckboxes ? col [ 0 ] + 1 : col [ 0 ] - 1 ;
128
+ col [ 0 ] = col [ 0 ] < 0 ? 0 : col [ 0 ] ; //no negative col numbers
129
+ } ) ;
130
+ }
131
+
120
132
// Need to deep watch changes in dtOptions and items
121
133
prevDtOptions = angular . copy ( ctrl . dtOptions ) ;
122
134
prevItems = angular . copy ( ctrl . items ) ;
123
135
prevPageConfig = angular . copy ( ctrl . pageConfig ) ;
124
-
125
- // Setting bound variables to new variables loses it's one way binding
126
- // ctrl.dtOptions = pfUtils.merge(ctrl.defaultDtOptions, ctrl.dtOptions);
127
- // ctrl.config = pfUtils.merge(ctrl.defaultConfig, ctrl.config);
128
-
129
- // Instead, use _.defaults to update the existing variable
130
- _ . defaults ( ctrl . dtOptions , ctrl . defaultDtOptions ) ;
131
- _ . defaults ( ctrl . config , ctrl . defaultConfig ) ;
132
- // may need to use _.defaultsDeep, but not currently available in
133
- // lodash-amd a-pf is using
136
+ prevShowCheckboxes = angular . copy ( ctrl . config . showCheckboxes ) ;
134
137
135
138
if ( ! validSelectionMatchProp ( ) ) {
136
139
angular . forEach ( ctrl . columns , function ( col ) {
0 commit comments