user1827423
user1827423

Reputation: 165

Scroll to end to grid UI-Grid Angular js

I want to scroll to end of the grid when data is loaded. But the code is not working. Please help

$scope.addData = function () {
        var n = $scope.gridOptions.data.length + 1;
        $scope.gridOptions.data.push({
                     "type":"student",
                    "is_job_ready":"true",
                     "is_night_shift":"true"
                 });
    $scope.scrollTo($scope.gridOptions.data.length -1,0)
    };

$scope.scrollTo = function( rowIndex, colIndex ) {
        $scope.gridApi.core.scrollTo( $scope.gridOptions.data[rowIndex],$scope.gridOptions.columnDefs[colIndex]);
};

Upvotes: 2

Views: 3856

Answers (2)

Gary
Gary

Reputation: 3324

Unfortunately, it seems it is still necessary to use $timeout

For example

$timeout(function () {
    // Do this after the columns and rows processors have finished and it is all rendered.
    $scope.gridApi.core.scrollTo($scope.gridOptions.data[$scope.gridOptions.data.length - 1], $scope.gridOptions.columnDefs[0]);
}, 100);

This is even after I tried waiting on modifyRows like this in my code

gridApi.grid.modifyRows(list).then(function () {
    // Do this after the columns and rows processors have finished and it is all rendered.
    gridApi.selection.selectRow(list[rowIndex]);
    gridApi.core.scrollTo(list[rowIndex], grid.columnDefs[0]);
});

Upvotes: 1

grzeshtoph
grzeshtoph

Reputation: 324

You need to include this module into your js code:

ui.grid.cellNav

Then, this scroll is going to work:

$scope.gridApi.core.scrollTo($scope.gridOptions.data[$scope.gridOptions.data.length - 1], $scope.gridOptions.columnDefs[0]);

Upvotes: 4

Related Questions