Skip to content

Commit 679b615

Browse files
committed
Enh(selection): fix #2254 allow both header and row selection
1 parent cb3d84d commit 679b615

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

misc/tutorial/210_selection.ngdoc

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ By default the module will provide a row header with checkboxes that allow selec
1515
the `enableRowHeaderSelection` gridOption to false, then the row header is hidden and a click on the row will
1616
result in selection of that row. You can see that in this tutorial for grid1 by looking at your javascript console.
1717

18+
If you want to allow both clicking on the row, and also clicking on the rowHeader, you can set `enableFullRowSelection` to
19+
true.
20+
1821
Setting the `multiSelect` gridOption to true will allow selecting multiple rows, setting to false will allow selection
1922
of only one row at a time.
2023

@@ -98,7 +101,12 @@ auto-selects the first row once the data is loaded.
98101
$scope.toggleRow1 = function() {
99102
$scope.gridApi.selection.toggleRowSelection($scope.gridOptions.data[0]);
100103
};
101-
104+
105+
$scope.toggleFullRowSelection = function() {
106+
$scope.gridOptions.enableFullRowSelection = !$scope.gridOptions.enableFullRowSelection;
107+
$scope.gridApi.core.notifyDataChange( uiGridConstants.dataChange.OPTIONS);
108+
};
109+
102110
$scope.setSelectable = function() {
103111
$scope.gridApi.selection.clearSelectedRows();
104112

@@ -174,6 +182,7 @@ auto-selects the first row once the data is loaded.
174182
<button type="button" class="btn btn-success" ng-disabled="!gridApi.grid.options.multiSelect" ng-click="selectAll()">Select All</button>
175183
<button type="button" class="btn btn-success" ng-click="clearAll()">Clear All</button>
176184
<button type="button" class="btn btn-success" ng-click="setSelectable()">Set Selectable</button>
185+
<button type="button" class="btn btn-success" ng-click="toggleFullRowSelection()">Toggle full row selection</button>
177186
<br/>
178187

179188
<div ui-grid="gridOptions" ui-grid-selection class="grid"></div>

src/features/selection/js/selection.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,16 @@
388388
* <br/>Defaults to true
389389
*/
390390
gridOptions.enableRowHeaderSelection = gridOptions.enableRowHeaderSelection !== false;
391+
/**
392+
* @ngdoc object
393+
* @name enableFullRowSelection
394+
* @propertyOf ui.grid.selection.api:GridOptions
395+
* @description Enable selection by clicking anywhere on the row. Defaults to
396+
* false if `enableRowHeaderSelection` is true, otherwise defaults to false.
397+
*/
398+
if ( typeof(gridOptions.enableFullRowSelection) === 'undefined' ){
399+
gridOptions.enableFullRowSelection = !gridOptions.enableRowHeaderSelection;
400+
}
391401
/**
392402
* @ngdoc object
393403
* @name enableSelectAll
@@ -874,7 +884,7 @@
874884
};
875885

876886
function registerRowSelectionEvents() {
877-
if ($scope.grid.options.enableRowSelection && !$scope.grid.options.enableRowHeaderSelection) {
887+
if ($scope.grid.options.enableRowSelection && $scope.grid.options.enableFullRowSelection) {
878888
$elm.addClass('ui-grid-disable-selection');
879889
$elm.on('touchstart', touchStart);
880890
$elm.on('touchend', touchEnd);
@@ -900,10 +910,10 @@
900910
// register a dataChange callback so that we can change the selection configuration dynamically
901911
// if the user changes the options
902912
var dataChangeDereg = $scope.grid.registerDataChangeCallback( function() {
903-
if ( $scope.grid.options.enableRowSelection && !$scope.grid.options.enableRowHeaderSelection &&
913+
if ( $scope.grid.options.enableRowSelection && $scope.grid.options.enableFullRowSelection &&
904914
!$scope.registered ){
905915
registerRowSelectionEvents();
906-
} else if ( ( !$scope.grid.options.enableRowSelection || $scope.grid.options.enableRowHeaderSelection ) &&
916+
} else if ( ( !$scope.grid.options.enableRowSelection || !$scope.grid.options.enableFullRowSelection ) &&
907917
$scope.registered ){
908918
deregisterRowSelectionEvents();
909919
}

0 commit comments

Comments
 (0)