Ui-grid scrollToFocus when sorting is applied to grid
I have a problem setting focus to the first line in a grid using the scrollToFocus method.
The problem seems to be centered around the direction of the sort:
sort: {
direction: uiGridConstants.DESC
}
If I leave this it works as expected. I can only assume that the line number is the data line before sorting it and does not take into account the "post" sorting.
Here's an example of the problem: http://plnkr.co/edit/beWci0?p=preview
You will see that when you click on the first row, it actually navigates to another row - the first in the dataset to which the grid is bound.
Any ideas on how to get involved in posting row position based on sorted results?
It was compiled from an example cropping: http://ui-grid.info/docs/#/tutorial/202_cellnav
source to share
If you want to select the first row in the grid regardless of sorting and filtering, you have to look at the visible rows, ui-grid does not display all the rows in the data array. Thus, the number of lines visible may be less than the actual data lines.
To select the first row, you can do the following:
$scope.scrollToFocus = function( rowIndex, colIndex ) {
var row = $scope.gridApi.grid.getVisibleRows()[rowIndex].entity;
$scope.gridApi.cellNav.scrollToFocus( row, $scope.gridOptions.columnDefs[colIndex]);
};
This will select the first visible row and set focus on the third column. Plnkr here http://plnkr.co/edit/gWlY68?p=preview
source to share