滚动到结束网格UI-Grid Angular js

时间:2015-06-01 05:27:10

标签: javascript jquery angularjs

我希望在加载数据时滚动到网格的末尾。但是代码不起作用。请帮忙

$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 个答案:

答案 0 :(得分:4)

您需要将此模块包含在您的js代码中:

ui.grid.cellNav

然后,这个卷轴将起作用:

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

答案 1 :(得分:0)

不幸的是,似乎仍然需要使用$timeout

例如

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

在我的代码

中尝试等待这样的modifyRows之后
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]);
});