Skip to content

Commit

Permalink
Merge pull request #3570 from PaulL1/treebase
Browse files Browse the repository at this point in the history
Various fixes
  • Loading branch information
PaulL1 committed May 23, 2015
2 parents 11b83eb + 664daee commit 363e4a5
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 10 deletions.
3 changes: 2 additions & 1 deletion misc/tutorial/103_filtering.ngdoc
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ Refer the {@link 499_FAQ FAQ}, it is possible to implement this using a rowsProc
{ field: 'age', filters: [
{
condition: uiGridConstants.filter.GREATER_THAN,
placeholder: 'greater than'
placeholder: 'greater than',
term: 30
},
{
condition: uiGridConstants.filter.LESS_THAN,
Expand Down
21 changes: 19 additions & 2 deletions misc/tutorial/320_complex_grouping.ngdoc
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ We create a custom columnsProcessor to override the default aggregation that gro
setting a custom aggregation function so that we can aggregate data from a different column than the
one we're on.

We turn on the ability to select group headers, and write a callback on the selection event to select all
children of the selected rowHeader.

@example
<example module="app">
<file name="app.js">
var app = angular.module('app', ['ngAnimate', 'ngTouch', 'ui.grid', 'ui.grid.grouping', 'ui.grid.edit' ]);
var app = angular.module('app', ['ngAnimate', 'ngTouch', 'ui.grid', 'ui.grid.grouping', 'ui.grid.edit', 'ui.grid.selection' ]);

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

$scope.gridOptions = {
enableFiltering: true,
enableGroupHeaderSelection: true,
columnDefs: [
{ name: 'name', width: '30%' },
{ name: 'gender', grouping: { groupPriority: 1 }, sort: { priority: 1, direction: 'asc' }, editableCellTemplate: 'ui-grid/dropdownEditor', width: '20%',
Expand All @@ -57,6 +61,19 @@ one we're on.
onRegisterApi: function( gridApi ) {
$scope.gridApi = gridApi;
$scope.gridApi.grid.registerColumnsProcessor( setGroupValues, 410 );
$scope.gridApi.selection.on.rowSelectionChanged( $scope, function ( rowChanged ) {
if ( typeof(rowChanged.treeLevel) !== 'undefined' && rowChanged.treeLevel > -1 ) {
// this is a group header
children = $scope.gridApi.treeBase.getRowChildren( rowChanged );
children.forEach( function ( child ) {
if ( rowChanged.isSelected ) {
$scope.gridApi.selection.selectRow( child.entity );
} else {
$scope.gridApi.selection.unSelectRow( child.entity );
}
});
}
});
}
};

Expand Down Expand Up @@ -96,7 +113,7 @@ one we're on.

<file name="index.html">
<div ng-controller="MainCtrl">
<div id="grid1" ui-grid="gridOptions" ui-grid-grouping ui-grid-edit class="grid"></div>
<div id="grid1" ui-grid="gridOptions" ui-grid-grouping ui-grid-edit ui-grid-selection class="grid"></div>
</div>
</file>

Expand Down
1 change: 1 addition & 0 deletions src/features/exporter/test/exporter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ describe('ui.grid.exporter uiGridExporterService', function () {
grid.rows[1].visible = false;
grid.columns[2].visible = false;
grid.setVisibleRows(grid.rows);
grid.setVisibleColumns(grid.columns);

grid.api.selection.clearSelectedRows();
grid.api.selection.selectRow(grid.rows[0].entity);
Expand Down
11 changes: 10 additions & 1 deletion src/features/grouping/js/grouping.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,15 @@
* <br/>Defaults to "Null"
*/
gridOptions.groupingNullLabel = gridOptions.groupingNullLabel || 'Null';

/**
* @ngdoc object
* @name enableGroupHeaderSelection
* @propertyOf ui.grid.grouping.api:GridOptions
* @description Allows group header rows to be selected.
* <br/>Defaults to false
*/
gridOptions.enableGroupHeaderSelection = gridOptions.enableGroupHeaderSelection === true;
},


Expand Down Expand Up @@ -1001,7 +1010,7 @@
headerRow.groupHeader = true;
headerRow.internalRow = true;
headerRow.enableCellEdit = false;
headerRow.enableSelection = false;
headerRow.enableSelection = grid.options.enableGroupHeaderSelection;
processingState[stateIndex].initialised = true;
processingState[stateIndex].currentValue = newValue;
processingState[stateIndex].currentRow = headerRow;
Expand Down
4 changes: 2 additions & 2 deletions src/features/grouping/test/grouping.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ddescribe('ui.grid.grouping uiGridGroupingService', function () {
describe('ui.grid.grouping uiGridGroupingService', function () {
var uiGridGroupingService;
var uiGridGroupingConstants;
var gridClassFactory;
Expand Down Expand Up @@ -295,7 +295,7 @@ ddescribe('ui.grid.grouping uiGridGroupingService', function () {
});


ddescribe('getGrouping via api (returns colName)', function() {
describe('getGrouping via api (returns colName)', function() {
it('should find no grouping', function() {
expect(grid.api.grouping.getGrouping( true )).toEqual({
grouping: [],
Expand Down
4 changes: 2 additions & 2 deletions src/features/row-edit/js/gridRowEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
* </pre>
* and somewhere within the event handler:
* <pre>
* gridApi.rowEdit.setSavePromise( grid, rowEntity, savePromise)
* gridApi.rowEdit.setSavePromise( rowEntity, savePromise)
* </pre>
* @param {object} rowEntity the options.data element that was edited
* @returns {promise} Your saveRow method should return a promise, the
Expand All @@ -91,7 +91,7 @@
* @description Sets the promise associated with the row save, mandatory that
* the saveRow event handler calls this method somewhere before returning.
* <pre>
* gridApi.rowEdit.setSavePromise(grid, rowEntity)
* gridApi.rowEdit.setSavePromise(rowEntity, savePromise)
* </pre>
* @param {object} rowEntity a data row from the grid for which a save has
* been initiated
Expand Down
15 changes: 15 additions & 0 deletions src/features/tree-base/js/tree-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,21 @@
*/
setTreeState: function ( config ) {
service.setTreeState( grid, config );
},

/**
* @ngdoc function
* @name getRowChildren
* @methodOf ui.grid.treeBase.api:PublicApi
* @description Get the children of the specified row
* @param {GridRow} row the row you want the children of
* @returns {Array} array of children of this row, the children
* are all gridRows
*/
getRowChildren: function ( row ){
return row.treeNode.children.map( function( childNode ){
return childNode.row;
});
}
}
}
Expand Down
9 changes: 8 additions & 1 deletion src/features/tree-base/test/tree-base.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ddescribe('ui.grid.treeBase uiGridTreeBaseService', function () {
describe('ui.grid.treeBase uiGridTreeBaseService', function () {
var uiGridTreeBaseService;
var uiGridTreeBaseConstants;
var gridClassFactory;
Expand Down Expand Up @@ -158,6 +158,13 @@ ddescribe('ui.grid.treeBase uiGridTreeBaseService', function () {
expect( treeRows.length ).toEqual( 2, 'only level 0 is visible' );
expect( collapseCount ).toEqual( 10 );
});

it( 'getRowChildren', function() {
expect( treeRows.length ).toEqual( 2, 'only the level 0 rows are visible' );

treeRows = uiGridTreeBaseService.treeRows.call( grid, grid.rows.slice(0) );
expect( grid.api.treeBase.getRowChildren( grid.rows[7] ).length ).toEqual(2);
});
});


Expand Down
2 changes: 1 addition & 1 deletion src/js/core/services/rowSearcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ module.service('rowSearcher', ['gridUtil', 'uiGridConstants', function (gridUtil
return !regex.exec(value);
}

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

0 comments on commit 363e4a5

Please sign in to comment.