Skip to content

Commit 363e4a5

Browse files
committed
Merge pull request #3570 from PaulL1/treebase
Various fixes
2 parents 11b83eb + 664daee commit 363e4a5

File tree

9 files changed

+60
-10
lines changed

9 files changed

+60
-10
lines changed

misc/tutorial/103_filtering.ngdoc

+2-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ Refer the {@link 499_FAQ FAQ}, it is possible to implement this using a rowsProc
139139
{ field: 'age', filters: [
140140
{
141141
condition: uiGridConstants.filter.GREATER_THAN,
142-
placeholder: 'greater than'
142+
placeholder: 'greater than',
143+
term: 30
143144
},
144145
{
145146
condition: uiGridConstants.filter.LESS_THAN,

misc/tutorial/320_complex_grouping.ngdoc

+19-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@ We create a custom columnsProcessor to override the default aggregation that gro
77
setting a custom aggregation function so that we can aggregate data from a different column than the
88
one we're on.
99

10+
We turn on the ability to select group headers, and write a callback on the selection event to select all
11+
children of the selected rowHeader.
12+
1013
@example
1114
<example module="app">
1215
<file name="app.js">
13-
var app = angular.module('app', ['ngAnimate', 'ngTouch', 'ui.grid', 'ui.grid.grouping', 'ui.grid.edit' ]);
16+
var app = angular.module('app', ['ngAnimate', 'ngTouch', 'ui.grid', 'ui.grid.grouping', 'ui.grid.edit', 'ui.grid.selection' ]);
1417

1518
app.controller('MainCtrl', ['$scope', '$http', '$interval', 'uiGridGroupingConstants', '$filter', function ($scope, $http, $interval, uiGridGroupingConstants, $filter ) {
1619
var setGroupValues = function( columns, rows ) {
@@ -39,6 +42,7 @@ one we're on.
3942

4043
$scope.gridOptions = {
4144
enableFiltering: true,
45+
enableGroupHeaderSelection: true,
4246
columnDefs: [
4347
{ name: 'name', width: '30%' },
4448
{ name: 'gender', grouping: { groupPriority: 1 }, sort: { priority: 1, direction: 'asc' }, editableCellTemplate: 'ui-grid/dropdownEditor', width: '20%',
@@ -57,6 +61,19 @@ one we're on.
5761
onRegisterApi: function( gridApi ) {
5862
$scope.gridApi = gridApi;
5963
$scope.gridApi.grid.registerColumnsProcessor( setGroupValues, 410 );
64+
$scope.gridApi.selection.on.rowSelectionChanged( $scope, function ( rowChanged ) {
65+
if ( typeof(rowChanged.treeLevel) !== 'undefined' && rowChanged.treeLevel > -1 ) {
66+
// this is a group header
67+
children = $scope.gridApi.treeBase.getRowChildren( rowChanged );
68+
children.forEach( function ( child ) {
69+
if ( rowChanged.isSelected ) {
70+
$scope.gridApi.selection.selectRow( child.entity );
71+
} else {
72+
$scope.gridApi.selection.unSelectRow( child.entity );
73+
}
74+
});
75+
}
76+
});
6077
}
6178
};
6279

@@ -96,7 +113,7 @@ one we're on.
96113

97114
<file name="index.html">
98115
<div ng-controller="MainCtrl">
99-
<div id="grid1" ui-grid="gridOptions" ui-grid-grouping ui-grid-edit class="grid"></div>
116+
<div id="grid1" ui-grid="gridOptions" ui-grid-grouping ui-grid-edit ui-grid-selection class="grid"></div>
100117
</div>
101118
</file>
102119

src/features/exporter/test/exporter.spec.js

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ describe('ui.grid.exporter uiGridExporterService', function () {
4444
grid.rows[1].visible = false;
4545
grid.columns[2].visible = false;
4646
grid.setVisibleRows(grid.rows);
47+
grid.setVisibleColumns(grid.columns);
4748

4849
grid.api.selection.clearSelectedRows();
4950
grid.api.selection.selectRow(grid.rows[0].entity);

src/features/grouping/js/grouping.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,15 @@
333333
* <br/>Defaults to "Null"
334334
*/
335335
gridOptions.groupingNullLabel = gridOptions.groupingNullLabel || 'Null';
336+
337+
/**
338+
* @ngdoc object
339+
* @name enableGroupHeaderSelection
340+
* @propertyOf ui.grid.grouping.api:GridOptions
341+
* @description Allows group header rows to be selected.
342+
* <br/>Defaults to false
343+
*/
344+
gridOptions.enableGroupHeaderSelection = gridOptions.enableGroupHeaderSelection === true;
336345
},
337346

338347

@@ -1001,7 +1010,7 @@
10011010
headerRow.groupHeader = true;
10021011
headerRow.internalRow = true;
10031012
headerRow.enableCellEdit = false;
1004-
headerRow.enableSelection = false;
1013+
headerRow.enableSelection = grid.options.enableGroupHeaderSelection;
10051014
processingState[stateIndex].initialised = true;
10061015
processingState[stateIndex].currentValue = newValue;
10071016
processingState[stateIndex].currentRow = headerRow;

src/features/grouping/test/grouping.spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ddescribe('ui.grid.grouping uiGridGroupingService', function () {
1+
describe('ui.grid.grouping uiGridGroupingService', function () {
22
var uiGridGroupingService;
33
var uiGridGroupingConstants;
44
var gridClassFactory;
@@ -295,7 +295,7 @@ ddescribe('ui.grid.grouping uiGridGroupingService', function () {
295295
});
296296

297297

298-
ddescribe('getGrouping via api (returns colName)', function() {
298+
describe('getGrouping via api (returns colName)', function() {
299299
it('should find no grouping', function() {
300300
expect(grid.api.grouping.getGrouping( true )).toEqual({
301301
grouping: [],

src/features/row-edit/js/gridRowEdit.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
* </pre>
7272
* and somewhere within the event handler:
7373
* <pre>
74-
* gridApi.rowEdit.setSavePromise( grid, rowEntity, savePromise)
74+
* gridApi.rowEdit.setSavePromise( rowEntity, savePromise)
7575
* </pre>
7676
* @param {object} rowEntity the options.data element that was edited
7777
* @returns {promise} Your saveRow method should return a promise, the
@@ -91,7 +91,7 @@
9191
* @description Sets the promise associated with the row save, mandatory that
9292
* the saveRow event handler calls this method somewhere before returning.
9393
* <pre>
94-
* gridApi.rowEdit.setSavePromise(grid, rowEntity)
94+
* gridApi.rowEdit.setSavePromise(rowEntity, savePromise)
9595
* </pre>
9696
* @param {object} rowEntity a data row from the grid for which a save has
9797
* been initiated

src/features/tree-base/js/tree-base.js

+15
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,21 @@
397397
*/
398398
setTreeState: function ( config ) {
399399
service.setTreeState( grid, config );
400+
},
401+
402+
/**
403+
* @ngdoc function
404+
* @name getRowChildren
405+
* @methodOf ui.grid.treeBase.api:PublicApi
406+
* @description Get the children of the specified row
407+
* @param {GridRow} row the row you want the children of
408+
* @returns {Array} array of children of this row, the children
409+
* are all gridRows
410+
*/
411+
getRowChildren: function ( row ){
412+
return row.treeNode.children.map( function( childNode ){
413+
return childNode.row;
414+
});
400415
}
401416
}
402417
}

src/features/tree-base/test/tree-base.spec.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ddescribe('ui.grid.treeBase uiGridTreeBaseService', function () {
1+
describe('ui.grid.treeBase uiGridTreeBaseService', function () {
22
var uiGridTreeBaseService;
33
var uiGridTreeBaseConstants;
44
var gridClassFactory;
@@ -158,6 +158,13 @@ ddescribe('ui.grid.treeBase uiGridTreeBaseService', function () {
158158
expect( treeRows.length ).toEqual( 2, 'only level 0 is visible' );
159159
expect( collapseCount ).toEqual( 10 );
160160
});
161+
162+
it( 'getRowChildren', function() {
163+
expect( treeRows.length ).toEqual( 2, 'only the level 0 rows are visible' );
164+
165+
treeRows = uiGridTreeBaseService.treeRows.call( grid, grid.rows.slice(0) );
166+
expect( grid.api.treeBase.getRowChildren( grid.rows[7] ).length ).toEqual(2);
167+
});
161168
});
162169

163170

src/js/core/services/rowSearcher.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ module.service('rowSearcher', ['gridUtil', 'uiGridConstants', function (gridUtil
214214
return !regex.exec(value);
215215
}
216216

217-
if (typeof(value) === 'number'){
217+
if (typeof(value) === 'number' && typeof(term) === 'string' ){
218218
// if the term has a decimal in it, it comes through as '9\.4', we need to take out the \
219219
// the same for negative numbers
220220
// TODO: I suspect the right answer is to look at escapeRegExp at the top of this code file, maybe it's not needed?

0 commit comments

Comments
 (0)