Skip to content

Commit 052c232

Browse files
committed
refactor(core): Change scrolling events. Various performance improvements in scrolling
Before this change, scrolling Events were being fire for each render container. Now, a ScrollBegin and ScrollEnd event is fired once for the grid. ScrollTo methods were moved from cellNav into core and also changed to return a promise. BREAKING CHANGE: Two events are now emitted on scroll: grid.api.core.ScrollBegin grid.api.core.ScrollEnd Before: grid.api.core.ScrollEvent After: grid.api.core.ScrollBegin ScrollToIfNecessary and ScrollTo moved from cellNav to core and grid removed from arguments Before: grid.api.cellNav.ScrollToIfNecessary(grid, gridRow, gridCol) grid.api.cellNav.ScrollTo(grid, rowEntity, colDef) After: grid.api.core.ScrollToIfNecessary(gridRow, gridCol) grid.api.core.ScrollTo(rowEntity, colDef) GridEdit/cellNav When using cellNav, a cell no longer receives focus. Instead the viewport always receives focus. This eliminated many bugs associated with scrolling and focus. If you have a custom editor, you will no longer receive keyDown/Up events from the readonly cell. Use the cellNav api viewPortKeyDown to capture any needed keydown events. see GridEdit.js for an example
1 parent 0bfc877 commit 052c232

24 files changed

+1006
-617
lines changed

misc/tutorial/202_cellnav.ngdoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ extract values of selected cells.
6868
};
6969

7070
$scope.scrollTo = function( rowIndex, colIndex ) {
71-
$scope.gridApi.cellNav.scrollTo( $scope.gridOptions.data[rowIndex], $scope.gridOptions.columnDefs[colIndex]);
71+
$scope.gridApi.core.scrollTo( $scope.gridOptions.data[rowIndex], $scope.gridOptions.columnDefs[colIndex]);
7272
};
7373

7474
$scope.scrollToFocus = function( rowIndex, colIndex ) {

misc/tutorial/211_two_grids.ngdoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ each other.
1818
};
1919

2020
$scope.scrollTo = function( rowIndex, colIndex ) {
21-
$scope.gridApi.cellNav.scrollTo( $scope.gridOptions.data[rowIndex], $scope.gridOptions.columnDefs[colIndex]);
21+
$scope.gridApi.core.scrollTo( $scope.gridOptions.data[rowIndex], $scope.gridOptions.columnDefs[colIndex]);
2222
};
2323

2424
$http.get('/data/100.json')

src/features/cellnav/js/cellnav.js

+135-298
Large diffs are not rendered by default.

src/features/cellnav/test/uiGridCellNavDirective.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ describe('ui.grid.cellNav directive', function () {
3333

3434
it('should not throw exceptions when scrolling when a grid does NOT have the ui-grid-cellNav directive', function () {
3535
expect(function () {
36-
$scope.gridApi.core.raise.scrollEvent({});
36+
$scope.gridApi.core.raise.scrollBegin({});
3737
}).not.toThrow();
3838
});
3939

src/features/cellnav/test/uiGridCellNavService.spec.js

+52-18
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,23 @@ describe('ui.grid.edit uiGridCellNavService', function () {
55
var uiGridConstants;
66
var uiGridCellNavConstants;
77
var $rootScope;
8+
var $timeout;
89

910
beforeEach(module('ui.grid.cellNav'));
1011

11-
beforeEach(inject(function (_uiGridCellNavService_, _gridClassFactory_, $templateCache, _uiGridConstants_, _uiGridCellNavConstants_, _$rootScope_) {
12+
beforeEach(inject(function (_uiGridCellNavService_, _gridClassFactory_, $templateCache, _uiGridConstants_, _uiGridCellNavConstants_, _$rootScope_, _$timeout_) {
1213
uiGridCellNavService = _uiGridCellNavService_;
1314
gridClassFactory = _gridClassFactory_;
1415
uiGridConstants = _uiGridConstants_;
1516
uiGridCellNavConstants = _uiGridCellNavConstants_;
1617
$rootScope = _$rootScope_;
18+
$timeout = _$timeout_;
1719

1820
$templateCache.put('ui-grid/uiGridCell', '<div/>');
1921

2022
grid = gridClassFactory.createGrid();
23+
//throttled scrolling isn't working in tests for some reason
24+
grid.options.scrollDebounce = 0;
2125
grid.options.columnDefs = [
2226
{name: 'col0', allowCellFocus: true},
2327
{name: 'col1', allowCellFocus: false},
@@ -192,15 +196,17 @@ describe('ui.grid.edit uiGridCellNavService', function () {
192196

193197
grid.setVisibleColumns(grid.columns);
194198
grid.setVisibleRows(grid.rows);
195-
199+
200+
grid.renderContainers.body.headerHeight = 0;
201+
196202
for ( i = 0; i < 11; i++ ){
197203
grid.columns[i].drawnWidth = i < 6 ? 100 : 200;
198204
}
199205

200206
$scope = $rootScope.$new();
201207

202208
args = null;
203-
grid.api.core.on.scrollEvent($scope, function( receivedArgs ){
209+
grid.api.core.on.scrollEnd($scope, function( receivedArgs ){
204210
args = receivedArgs;
205211
});
206212

@@ -211,51 +217,79 @@ describe('ui.grid.edit uiGridCellNavService', function () {
211217
// but it means these unit tests are now mostly checking that it is the same it used to
212218
// be, not that it is giving some specified result (i.e. I just updated them to what they were)
213219
it('should request scroll to row and column', function () {
214-
uiGridCellNavService.scrollTo( grid, grid.options.data[4], grid.columns[4].colDef);
215-
220+
$timeout(function () {
221+
grid.scrollTo(grid.options.data[4], grid.columns[4].colDef);
222+
});
223+
$timeout.flush();
224+
216225
expect(args.grid).toEqual(grid);
217-
expect(args.y).toEqual( { percentage : 5/11 });
226+
expect(args.y.percentage).toBe(0.41515151515151516);
218227
expect(isNaN(args.x.percentage)).toEqual( true );
219228
});
220229

221230
it('should request scroll to row only - first row', function () {
222-
uiGridCellNavService.scrollTo( grid, grid.options.data[0], null);
231+
$timeout(function () {
232+
grid.scrollTo( grid.options.data[0], null);
233+
});
234+
$timeout.flush();
223235

224-
expect(args.y).toEqual( { percentage : 2/11 });
236+
expect(args.y.percentage).toBe(0.14242424242424243);
225237
});
226238

227239
it('should request scroll to row only - last row', function () {
228-
uiGridCellNavService.scrollTo( grid, grid.options.data[10], null);
240+
$timeout(function () {
241+
grid.scrollTo( grid.options.data[10], null);
242+
});
243+
$timeout.flush();
229244

230-
expect(args.y).toEqual( { percentage : 1 });
245+
expect(args.y.percentage).toBeGreaterThan(0.5);
246+
expect(args.x).toBe(null);
231247
});
232248

233249
it('should request scroll to row only - row 4', function () {
234-
uiGridCellNavService.scrollTo( grid, grid.options.data[5], null);
250+
$timeout(function () {
251+
grid.scrollTo( grid.options.data[5], null);
252+
});
253+
$timeout.flush();
235254

236-
expect(args.y).toEqual( { percentage : 6/11 });
255+
expect(args.y.percentage).toEqual( 0.5060606060606061);
256+
expect(args.x).toBe(null);
237257
});
238258

239259
it('should request scroll to column only - first column', function () {
240-
uiGridCellNavService.scrollTo( grid, null, grid.columns[0].colDef);
241-
260+
$timeout(function () {
261+
grid.scrollTo( null, grid.columns[0].colDef);
262+
});
263+
$timeout.flush();
264+
265+
242266
expect(isNaN(args.x.percentage)).toEqual( true );
243267
});
244268

245269
it('should request scroll to column only - last column', function () {
246-
uiGridCellNavService.scrollTo( grid, null, grid.columns[10].colDef);
247-
270+
$timeout(function () {
271+
grid.scrollTo( null, grid.columns[10].colDef);
272+
});
273+
$timeout.flush();
274+
275+
248276
expect(isNaN(args.x.percentage)).toEqual( true );
249277
});
250278

251279
it('should request scroll to column only - column 7', function () {
252-
uiGridCellNavService.scrollTo( grid, null, grid.columns[8].colDef);
280+
$timeout(function () {
281+
grid.scrollTo( null, grid.columns[8].colDef);
282+
});
283+
$timeout.flush();
253284

254285
expect(isNaN(args.x.percentage)).toEqual( true );
255286
});
256287

257288
it('should request no scroll as no row or column', function () {
258-
uiGridCellNavService.scrollTo( grid, null, null );
289+
$timeout(function () {
290+
grid.scrollTo( null, null );
291+
});
292+
$timeout.flush();
259293

260294
expect(args).toEqual( null );
261295
});

0 commit comments

Comments
 (0)