Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 32 additions & 12 deletions src/features/cellnav/js/cellnav.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,30 +290,49 @@
/**
* @ngdoc method
* @methodOf ui.grid.cellNav.service:uiGridCellNavService
* @name scrollVerticallyTo
* @description Scroll the grid vertically such that the specified
* row is in view
* @name scrollTo
* @description Scroll the grid such that the specified
* row and column is in view
* @param {Grid} grid the grid you'd like to act upon, usually available
* from gridApi.grid
* @param {object} $scope a scope we can broadcast events from
* @param {object} rowEntity gridOptions.data[] array instance to make visible
* @param {object} colDef to make visible
*/
scrollTo: function (grid, $scope, rowEntity, colDef) {
var args = {};
var gridRow = null, gridCol = null;

if ( rowEntity !== null ){
var row = grid.getRow(rowEntity);
if ( row ) {
args.y = { percentage: row.index / grid.renderContainers.body.visibleRowCache.length };
}
gridRow = grid.getRow(rowEntity);
}

if ( colDef !== null ){
var col = grid.getColumn(colDef.name ? colDef.name : colDef.field);
if ( col ) {
args.x = { percentage: this.getLeftWidth(grid, col.index) / this.getLeftWidth(grid, grid.renderContainers.body.visibleColumnCache.length - 1) };
}
gridCol = grid.getColumn(colDef.name ? colDef.name : colDef.field);
}
this.scrollToInternal(grid, $scope, gridRow, gridCol);
},


/**
* @ngdoc method
* @methodOf ui.grid.cellNav.service:uiGridCellNavService
* @name scrollToInternal
* @description Like scrollTo, but takes gridRow and gridCol
* @param {Grid} grid the grid you'd like to act upon, usually available
* from gridApi.grid
* @param {object} $scope a scope we can broadcast events from
* @param {GridRow} gridRow row to make visible
* @param {GridCol} gridCol column to make visible
*/
scrollToInternal: function( grid, $scope, gridRow, gridCol ){
var args = {};

if ( gridRow !== null ){
args.y = { percentage: gridRow.index / grid.renderContainers.body.visibleRowCache.length };
}

if ( gridCol !== null ){
args.x = { percentage: this.getLeftWidth(grid, gridCol.index) / this.getLeftWidth(grid, grid.renderContainers.body.visibleColumnCache.length - 1) };
}

if ( args.y || args.x ){
Expand Down Expand Up @@ -477,6 +496,7 @@
var div = $elm.find('div');
div[0].focus();
div.attr("tabindex", 0);
$scope.grid.queueRefresh();
}

}
Expand Down
7 changes: 6 additions & 1 deletion src/js/core/factories/Grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ angular.module('ui.grid')
Grid.prototype.addRowHeaderColumn = function addRowHeaderColumn(colDef) {
var self = this;
//self.createLeftContainer();
var rowHeaderCol = new GridColumn(colDef, self.rowHeaderColumns.length + 1, self);
var rowHeaderCol = new GridColumn(colDef, self.rowHeaderColumns.length, self);
rowHeaderCol.isRowHeader = true;
if (self.isRTL()) {
self.createRightContainer();
Expand Down Expand Up @@ -351,6 +351,11 @@ angular.module('ui.grid')
angular.forEach(self.rowHeaderColumns, function (rowHeaderColumn) {
offset++;
self.columns.unshift(rowHeaderColumn);

// renumber any columns already there, as cellNav relies on cols[index] === col.index
self.columns.forEach(function(column, index){
column.index = index;
});
});


Expand Down
3 changes: 2 additions & 1 deletion src/js/core/services/gridClassFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@
* @name cellTemplate
* @propertyOf ui.grid.class:GridOptions.columnDef
* @description a custom template for each cell in this column. The default
* is ui-grid/uiGridCell
* is ui-grid/uiGridCell. If you are using the cellNav feature, this template
* must contain a div that can receive focus.
*
*/
if (!colDef.cellTemplate) {
Expand Down