Skip to content

Commit 7ccd3cc

Browse files
committed
Merge pull request #1609 from PaulL1/1608_cellnav_skipping
Fix #1608 - cellNav skipping every second col
2 parents ff41311 + 6ee0b0b commit 7ccd3cc

File tree

3 files changed

+40
-14
lines changed

3 files changed

+40
-14
lines changed

src/features/cellnav/js/cellnav.js

+32-12
Original file line numberDiff line numberDiff line change
@@ -290,30 +290,49 @@
290290
/**
291291
* @ngdoc method
292292
* @methodOf ui.grid.cellNav.service:uiGridCellNavService
293-
* @name scrollVerticallyTo
294-
* @description Scroll the grid vertically such that the specified
295-
* row is in view
293+
* @name scrollTo
294+
* @description Scroll the grid such that the specified
295+
* row and column is in view
296296
* @param {Grid} grid the grid you'd like to act upon, usually available
297297
* from gridApi.grid
298298
* @param {object} $scope a scope we can broadcast events from
299299
* @param {object} rowEntity gridOptions.data[] array instance to make visible
300300
* @param {object} colDef to make visible
301301
*/
302302
scrollTo: function (grid, $scope, rowEntity, colDef) {
303-
var args = {};
303+
var gridRow = null, gridCol = null;
304304

305305
if ( rowEntity !== null ){
306-
var row = grid.getRow(rowEntity);
307-
if ( row ) {
308-
args.y = { percentage: row.index / grid.renderContainers.body.visibleRowCache.length };
309-
}
306+
gridRow = grid.getRow(rowEntity);
310307
}
311308

312309
if ( colDef !== null ){
313-
var col = grid.getColumn(colDef.name ? colDef.name : colDef.field);
314-
if ( col ) {
315-
args.x = { percentage: this.getLeftWidth(grid, col.index) / this.getLeftWidth(grid, grid.renderContainers.body.visibleColumnCache.length - 1) };
316-
}
310+
gridCol = grid.getColumn(colDef.name ? colDef.name : colDef.field);
311+
}
312+
this.scrollToInternal(grid, $scope, gridRow, gridCol);
313+
},
314+
315+
316+
/**
317+
* @ngdoc method
318+
* @methodOf ui.grid.cellNav.service:uiGridCellNavService
319+
* @name scrollToInternal
320+
* @description Like scrollTo, but takes gridRow and gridCol
321+
* @param {Grid} grid the grid you'd like to act upon, usually available
322+
* from gridApi.grid
323+
* @param {object} $scope a scope we can broadcast events from
324+
* @param {GridRow} gridRow row to make visible
325+
* @param {GridCol} gridCol column to make visible
326+
*/
327+
scrollToInternal: function( grid, $scope, gridRow, gridCol ){
328+
var args = {};
329+
330+
if ( gridRow !== null ){
331+
args.y = { percentage: gridRow.index / grid.renderContainers.body.visibleRowCache.length };
332+
}
333+
334+
if ( gridCol !== null ){
335+
args.x = { percentage: this.getLeftWidth(grid, gridCol.index) / this.getLeftWidth(grid, grid.renderContainers.body.visibleColumnCache.length - 1) };
317336
}
318337

319338
if ( args.y || args.x ){
@@ -477,6 +496,7 @@
477496
var div = $elm.find('div');
478497
div[0].focus();
479498
div.attr("tabindex", 0);
499+
$scope.grid.queueRefresh();
480500
}
481501

482502
}

src/js/core/factories/Grid.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ angular.module('ui.grid')
298298
Grid.prototype.addRowHeaderColumn = function addRowHeaderColumn(colDef) {
299299
var self = this;
300300
//self.createLeftContainer();
301-
var rowHeaderCol = new GridColumn(colDef, self.rowHeaderColumns.length + 1, self);
301+
var rowHeaderCol = new GridColumn(colDef, self.rowHeaderColumns.length, self);
302302
rowHeaderCol.isRowHeader = true;
303303
if (self.isRTL()) {
304304
self.createRightContainer();
@@ -351,6 +351,11 @@ angular.module('ui.grid')
351351
angular.forEach(self.rowHeaderColumns, function (rowHeaderColumn) {
352352
offset++;
353353
self.columns.unshift(rowHeaderColumn);
354+
355+
// renumber any columns already there, as cellNav relies on cols[index] === col.index
356+
self.columns.forEach(function(column, index){
357+
column.index = index;
358+
});
354359
});
355360

356361

src/js/core/services/gridClassFactory.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@
118118
* @name cellTemplate
119119
* @propertyOf ui.grid.class:GridOptions.columnDef
120120
* @description a custom template for each cell in this column. The default
121-
* is ui-grid/uiGridCell
121+
* is ui-grid/uiGridCell. If you are using the cellNav feature, this template
122+
* must contain a div that can receive focus.
122123
*
123124
*/
124125
if (!colDef.cellTemplate) {

0 commit comments

Comments
 (0)