Skip to content

Commit 21819c5

Browse files
nbulusanjrmportuga
authored andcommitted
fix(6160): Select childrens of row group (#6167)
* Update selection.js Select childrens of row group * format indentation * Change scrolling from scroll to auto. * Update test script
1 parent 9fb0765 commit 21819c5

File tree

3 files changed

+79
-74
lines changed

3 files changed

+79
-74
lines changed

src/features/selection/js/selection.js

+72-67
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
});
2929

3030
//add methods to GridRow
31-
angular.module('ui.grid').config(['$provide', function($provide) {
32-
$provide.decorator('GridRow', ['$delegate', function($delegate) {
31+
angular.module('ui.grid').config(['$provide', function ($provide) {
32+
$provide.decorator('GridRow', ['$delegate', function ($delegate) {
3333

3434
/**
3535
* @ngdoc object
@@ -57,20 +57,20 @@
5757
*/
5858

5959

60-
/**
61-
* @ngdoc function
62-
* @name setSelected
63-
* @methodOf ui.grid.selection.api:GridRow
64-
* @description Sets the isSelected property and updates the selectedCount
65-
* Changes to isSelected state should only be made via this function
66-
* @param {bool} selected value to set
67-
*/
68-
$delegate.prototype.setSelected = function(selected) {
69-
if (selected !== this.isSelected) {
70-
this.isSelected = selected;
71-
this.grid.selection.selectedCount += selected ? 1 : -1;
72-
}
73-
};
60+
/**
61+
* @ngdoc function
62+
* @name setSelected
63+
* @methodOf ui.grid.selection.api:GridRow
64+
* @description Sets the isSelected property and updates the selectedCount
65+
* Changes to isSelected state should only be made via this function
66+
* @param {bool} selected value to set
67+
*/
68+
$delegate.prototype.setSelected = function (selected) {
69+
if (selected !== this.isSelected) {
70+
this.isSelected = selected;
71+
this.grid.selection.selectedCount += selected ? 1 : -1;
72+
}
73+
};
7474

7575
return $delegate;
7676
}]);
@@ -188,9 +188,9 @@
188188
* @param {number} index index within the rowsVisible array
189189
* @param {Event} event object if raised from an event
190190
*/
191-
selectRowByVisibleIndex: function ( rowNum, evt ) {
191+
selectRowByVisibleIndex: function (rowNum, evt) {
192192
var row = grid.renderContainers.body.visibleRowCache[rowNum];
193-
if (row !== null && typeof(row) !== 'undefined' && !row.isSelected) {
193+
if (row !== null && typeof (row) !== 'undefined' && !row.isSelected) {
194194
service.toggleRowSelection(grid, row, evt, grid.options.multiSelect, grid.options.noUnselect);
195195
}
196196
},
@@ -222,12 +222,12 @@
222222

223223
var changedRows = [];
224224
grid.rows.forEach(function (row) {
225-
if ( !row.isSelected && row.enableSelection !== false ){
225+
if (!row.isSelected && row.enableSelection !== false) {
226226
row.setSelected(true);
227-
service.decideRaiseSelectionEvent( grid, row, changedRows, evt );
227+
service.decideRaiseSelectionEvent(grid, row, changedRows, evt);
228228
}
229229
});
230-
service.decideRaiseSelectionBatchEvent( grid, changedRows, evt );
230+
service.decideRaiseSelectionBatchEvent(grid, changedRows, evt);
231231
grid.selection.selectAll = true;
232232
},
233233
/**
@@ -245,18 +245,18 @@
245245
var changedRows = [];
246246
grid.rows.forEach(function (row) {
247247
if (row.visible) {
248-
if (!row.isSelected && row.enableSelection !== false){
248+
if (!row.isSelected && row.enableSelection !== false) {
249249
row.setSelected(true);
250-
service.decideRaiseSelectionEvent( grid, row, changedRows, evt );
250+
service.decideRaiseSelectionEvent(grid, row, changedRows, evt);
251251
}
252252
} else {
253-
if (row.isSelected){
253+
if (row.isSelected) {
254254
row.setSelected(false);
255-
service.decideRaiseSelectionEvent( grid, row, changedRows, evt );
255+
service.decideRaiseSelectionEvent(grid, row, changedRows, evt);
256256
}
257257
}
258258
});
259-
service.decideRaiseSelectionBatchEvent( grid, changedRows, evt );
259+
service.decideRaiseSelectionBatchEvent(grid, changedRows, evt);
260260
grid.selection.selectAll = true;
261261
},
262262
/**
@@ -401,7 +401,7 @@
401401
* @description Enable selection by clicking anywhere on the row. Defaults to
402402
* false if `enableRowHeaderSelection` is true, otherwise defaults to false.
403403
*/
404-
if ( typeof(gridOptions.enableFullRowSelection) === 'undefined' ){
404+
if (typeof (gridOptions.enableFullRowSelection) === 'undefined') {
405405
gridOptions.enableFullRowSelection = !gridOptions.enableRowHeaderSelection;
406406
}
407407
/**
@@ -466,7 +466,7 @@
466466
toggleRowSelection: function (grid, row, evt, multiSelect, noUnselect) {
467467
var selected = row.isSelected;
468468

469-
if ( row.enableSelection === false && !selected ){
469+
if (row.enableSelection === false && !selected) {
470470
return;
471471
}
472472

@@ -481,7 +481,7 @@
481481
}
482482
}
483483

484-
if (selected && noUnselect){
484+
if (selected && noUnselect) {
485485
// don't deselect the row
486486
} else {
487487
row.setSelected(!selected);
@@ -523,14 +523,14 @@
523523
for (var i = fromRow; i <= toRow; i++) {
524524
var rowToSelect = grid.renderContainers.body.visibleRowCache[i];
525525
if (rowToSelect) {
526-
if ( !rowToSelect.isSelected && rowToSelect.enableSelection !== false ){
526+
if (!rowToSelect.isSelected && rowToSelect.enableSelection !== false) {
527527
rowToSelect.setSelected(true);
528528
grid.selection.lastSelectedRow = rowToSelect;
529-
service.decideRaiseSelectionEvent( grid, rowToSelect, changedRows, evt );
529+
service.decideRaiseSelectionEvent(grid, rowToSelect, changedRows, evt);
530530
}
531531
}
532532
}
533-
service.decideRaiseSelectionBatchEvent( grid, changedRows, evt );
533+
service.decideRaiseSelectionBatchEvent(grid, changedRows, evt);
534534
},
535535
/**
536536
* @ngdoc function
@@ -556,12 +556,12 @@
556556
clearSelectedRows: function (grid, evt) {
557557
var changedRows = [];
558558
service.getSelectedRows(grid).forEach(function (row) {
559-
if ( row.isSelected ){
559+
if (row.isSelected) {
560560
row.setSelected(false);
561-
service.decideRaiseSelectionEvent( grid, row, changedRows, evt );
561+
service.decideRaiseSelectionEvent(grid, row, changedRows, evt);
562562
}
563563
});
564-
service.decideRaiseSelectionBatchEvent( grid, changedRows, evt );
564+
service.decideRaiseSelectionBatchEvent(grid, changedRows, evt);
565565
grid.selection.selectAll = false;
566566
grid.selection.selectedCount = 0;
567567
},
@@ -577,8 +577,8 @@
577577
* @param {Event} event object if raised from an event
578578
* row if we're doing batch events
579579
*/
580-
decideRaiseSelectionEvent: function( grid, row, changedRows, evt ){
581-
if ( !grid.options.enableSelectionBatchEvent ){
580+
decideRaiseSelectionEvent: function (grid, row, changedRows, evt) {
581+
if (!grid.options.enableSelectionBatchEvent) {
582582
grid.api.selection.raise.rowSelectionChanged(row, evt);
583583
} else {
584584
changedRows.push(row);
@@ -596,8 +596,8 @@
596596
* @param {Event} event object if raised from an event
597597
* if we're doing batch events
598598
*/
599-
decideRaiseSelectionBatchEvent: function( grid, changedRows, evt ){
600-
if ( changedRows.length > 0 ){
599+
decideRaiseSelectionBatchEvent: function (grid, changedRows, evt) {
600+
if (changedRows.length > 0) {
601601
grid.api.selection.raise.rowSelectionChangedBatch(changedRows, evt);
602602
}
603603
}
@@ -654,7 +654,7 @@
654654
var selectionRowHeaderDef = {
655655
name: uiGridSelectionConstants.selectionRowHeaderColName,
656656
displayName: '',
657-
width: uiGridCtrl.grid.options.selectionRowHeaderWidth,
657+
width: uiGridCtrl.grid.options.selectionRowHeaderWidth,
658658
minWidth: 10,
659659
cellTemplate: 'ui-grid/selectionRowHeader',
660660
headerCellTemplate: 'ui-grid/selectionHeaderCell',
@@ -669,14 +669,14 @@
669669

670670
var processorSet = false;
671671

672-
var processSelectableRows = function( rows ){
673-
rows.forEach(function(row){
672+
var processSelectableRows = function (rows) {
673+
rows.forEach(function (row) {
674674
row.enableSelection = uiGridCtrl.grid.options.isRowSelectable(row);
675675
});
676676
return rows;
677677
};
678678

679-
var updateOptions = function(){
679+
var updateOptions = function () {
680680
if (uiGridCtrl.grid.options.isRowSelectable !== angular.noop && processorSet !== true) {
681681
uiGridCtrl.grid.registerRowsProcessor(processSelectableRows, 500);
682682
processorSet = true;
@@ -685,9 +685,9 @@
685685

686686
updateOptions();
687687

688-
var dataChangeDereg = uiGridCtrl.grid.registerDataChangeCallback( updateOptions, [uiGridConstants.dataChange.OPTIONS] );
688+
var dataChangeDereg = uiGridCtrl.grid.registerDataChangeCallback(updateOptions, [uiGridConstants.dataChange.OPTIONS]);
689689

690-
$scope.$on( '$destroy', dataChangeDereg);
690+
$scope.$on('$destroy', dataChangeDereg);
691691
},
692692
post: function ($scope, $elm, $attrs, uiGridCtrl) {
693693

@@ -705,7 +705,7 @@
705705
template: $templateCache.get('ui-grid/selectionRowHeaderButtons'),
706706
scope: true,
707707
require: '^uiGrid',
708-
link: function($scope, $elm, $attrs, uiGridCtrl) {
708+
link: function ($scope, $elm, $attrs, uiGridCtrl) {
709709
var self = uiGridCtrl.grid;
710710
$scope.selectButtonClick = selectButtonClick;
711711

@@ -725,6 +725,11 @@
725725
else if (evt.ctrlKey || evt.metaKey) {
726726
uiGridSelectionService.toggleRowSelection(self, row, evt, self.options.multiSelect, self.options.noUnselect);
727727
}
728+
else if (row.groupHeader) {
729+
for (var i = 0; i < row.treeNode.children.length; i++) {
730+
uiGridSelectionService.toggleRowSelection(self, row.treeNode.children[i].row, evt, self.options.multiSelect, self.options.noUnselect);
731+
}
732+
}
728733
else {
729734
uiGridSelectionService.toggleRowSelection(self, row, evt, (self.options.multiSelect && !self.options.modifierKeysToMultiSelect), self.options.noUnselect);
730735
}
@@ -751,18 +756,18 @@
751756
restrict: 'E',
752757
template: $templateCache.get('ui-grid/selectionSelectAllButtons'),
753758
scope: false,
754-
link: function($scope, $elm, $attrs, uiGridCtrl) {
759+
link: function ($scope, $elm, $attrs, uiGridCtrl) {
755760
var self = $scope.col.grid;
756761

757-
$scope.headerButtonClick = function(row, evt) {
758-
if ( self.selection.selectAll ){
762+
$scope.headerButtonClick = function (row, evt) {
763+
if (self.selection.selectAll) {
759764
uiGridSelectionService.clearSelectedRows(self, evt);
760-
if ( self.options.noUnselect ){
765+
if (self.options.noUnselect) {
761766
self.api.selection.selectRowByVisibleIndex(0, evt);
762767
}
763768
self.selection.selectAll = false;
764769
} else {
765-
if ( self.options.multiSelect ){
770+
if (self.options.multiSelect) {
766771
self.api.selection.selectAllVisibleRows(evt);
767772
self.selection.selectAll = true;
768773
}
@@ -791,7 +796,7 @@
791796

792797
var existingNgClass = rowRepeatDiv.attr("ng-class");
793798
var newNgClass = '';
794-
if ( existingNgClass ) {
799+
if (existingNgClass) {
795800
newNgClass = existingNgClass.slice(0, -1) + ",'ui-grid-row-selected': row.isSelected}";
796801
} else {
797802
newNgClass = "{'ui-grid-row-selected': row.isSelected}";
@@ -845,7 +850,7 @@
845850
$scope.$apply();
846851
}
847852

848-
// uiGridCellNavService.scrollToIfNecessary(uiGridCtrl.grid, rowCol.row, rowCol.col);
853+
// uiGridCellNavService.scrollToIfNecessary(uiGridCtrl.grid, rowCol.row, rowCol.col);
849854
});
850855
}
851856

@@ -856,7 +861,7 @@
856861
// }
857862
//});
858863

859-
var selectCells = function(evt){
864+
var selectCells = function (evt) {
860865
// if you click on expandable icon doesn't trigger selection
861866
if (evt.target.className === "ui-grid-icon-minus-squared" || evt.target.className === "ui-grid-icon-plus-squared") {
862867
return;
@@ -878,30 +883,30 @@
878883

879884
// don't re-enable the touchend handler for a little while - some devices generate both, and it will
880885
// take a little while to move your hand from the mouse to the screen if you have both modes of input
881-
$timeout(function() {
886+
$timeout(function () {
882887
$elm.on('touchend', touchEnd);
883888
}, touchTimeout);
884889
};
885890

886-
var touchStart = function(evt){
891+
var touchStart = function (evt) {
887892
touchStartTime = (new Date()).getTime();
888893

889894
// if we get a touch event, then stop listening for click
890895
$elm.off('click', selectCells);
891896
};
892897

893-
var touchEnd = function(evt) {
898+
var touchEnd = function (evt) {
894899
var touchEndTime = (new Date()).getTime();
895900
var touchTime = touchEndTime - touchStartTime;
896901

897-
if (touchTime < touchTimeout ) {
902+
if (touchTime < touchTimeout) {
898903
// short touch
899904
selectCells(evt);
900905
}
901906

902907
// don't re-enable the click handler for a little while - some devices generate both, and it will
903908
// take a little while to move your hand from the screen to the mouse if you have both modes of input
904-
$timeout(function() {
909+
$timeout(function () {
905910
$elm.on('click', selectCells);
906911
}, touchTimeout);
907912
};
@@ -918,7 +923,7 @@
918923
}
919924

920925
function deregisterRowSelectionEvents() {
921-
if ($scope.registered){
926+
if ($scope.registered) {
922927
$elm.removeClass('ui-grid-disable-selection');
923928

924929
$elm.off('touchstart', touchStart);
@@ -932,17 +937,17 @@
932937
registerRowSelectionEvents();
933938
// register a dataChange callback so that we can change the selection configuration dynamically
934939
// if the user changes the options
935-
var dataChangeDereg = $scope.grid.registerDataChangeCallback( function() {
936-
if ( $scope.grid.options.enableRowSelection && $scope.grid.options.enableFullRowSelection &&
937-
!$scope.registered ){
940+
var dataChangeDereg = $scope.grid.registerDataChangeCallback(function () {
941+
if ($scope.grid.options.enableRowSelection && $scope.grid.options.enableFullRowSelection &&
942+
!$scope.registered) {
938943
registerRowSelectionEvents();
939-
} else if ( ( !$scope.grid.options.enableRowSelection || !$scope.grid.options.enableFullRowSelection ) &&
940-
$scope.registered ){
944+
} else if ((!$scope.grid.options.enableRowSelection || !$scope.grid.options.enableFullRowSelection) &&
945+
$scope.registered) {
941946
deregisterRowSelectionEvents();
942947
}
943-
}, [uiGridConstants.dataChange.OPTIONS] );
948+
}, [uiGridConstants.dataChange.OPTIONS]);
944949

945-
$elm.on( '$destroy', dataChangeDereg);
950+
$elm.on('$destroy', dataChangeDereg);
946951
}
947952
};
948953
}]);

src/js/core/factories/GridRenderContainer.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -779,8 +779,8 @@ angular.module('ui.grid')
779779
self.hasVScrollbar = !self.grid.isRTL() ? self.grid.options.enableVerticalScrollbar !== uiGridConstants.scrollbars.NEVER : false;
780780
}
781781

782-
styles['overflow-x'] = self.hasHScrollbar ? 'scroll' : 'hidden';
783-
styles['overflow-y'] = self.hasVScrollbar ? 'scroll' : 'hidden';
782+
styles['overflow-x'] = self.hasHScrollbar ? 'auto' : 'hidden';
783+
styles['overflow-y'] = self.hasVScrollbar ? 'auto' : 'hidden';
784784

785785

786786
return styles;

0 commit comments

Comments
 (0)