@@ -14,7 +14,7 @@ angular.module('patternfly.table').component('pfTableView', {
1414 templateUrl : 'table/tableview/table-view.html' ,
1515 controller : function ( DTOptionsBuilder , DTColumnDefBuilder , $element , pfUtils , $log , $filter , $timeout , $sce ) {
1616 'use strict' ;
17- var ctrl = this , prevDtOptions , prevItems , prevPageConfig ;
17+ var ctrl = this , prevDtOptions , prevItems , prevPageConfig , prevShowCheckboxes ;
1818
1919 // Once datatables is out of active development I'll remove log statements
2020 ctrl . debug = false ;
@@ -25,7 +25,7 @@ angular.module('patternfly.table').component('pfTableView', {
2525 ctrl . defaultDtOptions = {
2626 autoWidth : false ,
2727 destroy : true ,
28- order : [ [ 1 , "asc" ] ] ,
28+ order : [ [ 0 , "asc" ] ] , //default to 1st (col 0) for sorting, updateConfigOptions() will adjust based on showCheckboxes
2929 dom : "t" ,
3030 paging : false ,
3131 select : {
@@ -117,20 +117,23 @@ angular.module('patternfly.table').component('pfTableView', {
117117 ctrl . dtOptions . displayLength = Number ( ctrl . dtOptions . displayLength ) ;
118118 }
119119
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+
120132 // Need to deep watch changes in dtOptions and items
121133 prevDtOptions = angular . copy ( ctrl . dtOptions ) ;
122134 prevItems = angular . copy ( ctrl . items ) ;
123135 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 ) ;
134137
135138 if ( ! validSelectionMatchProp ( ) ) {
136139 angular . forEach ( ctrl . columns , function ( col ) {
0 commit comments