ng-grid不会滚动到最后一行

qor*_*ond 2 angularjs ng-grid

使用ng-grid我想通过在添加到列表底部时滚动到它来显示新添加的行.

请看看插件:http://plnkr.co/edit/4jgy9wwr2HRhfhgKMKcX?p = preview

var grid = $scope.gridOptions.ngGrid;
grid.$viewport.scrollTop((($scope.myData.length - 1)* grid.config.rowHeight));
Run Code Online (Sandbox Code Playgroud)

我不明白为什么网格不会一直向下滚动.我尝试添加rowHeight,但是每次网格都不会滚动到最后一行.

我知道通过将记录添加到列表顶部将解决问题我将对网格进行排序,并且其性质将空记录推送到底部.

mer*_*dec 9

你不需要"ngGridEventData",如果你记录它,你会发现他被你的网格上的每个现有行解雇了,这不是最佳的.

如前所述,您可以使用$ timeout服务,延迟时间为0.这听起来有点棘手,它可能不是最好的做法,但它确实有效.

将其加载到您的控制器中:

app.controller('MyCtrl', function($scope, $timeout) {
    //load
}
Run Code Online (Sandbox Code Playgroud)

然后在你的addNew()中:

$scope.addNew = function () {

    $scope.myData.push({ name: "new", age: 100 });

    $timeout(function () {
        var grid = $scope.gridOptions.ngGrid;
        $scope.gridOptions.selectItem($scope.myData.length - 1, true);
        grid.$viewport.scrollTop((($scope.myData.length - 1) * grid.config.rowHeight));
    }, 0);

};
Run Code Online (Sandbox Code Playgroud)

检查结果:http://plnkr.co/edit/4HNqFh7uu9IWCjDVt5WR?p = preview