2

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]);
};

2 Answers 2

4

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]);

Sign up to request clarification or add additional context in comments.

Comments

1

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]);
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.