2015-06-01 61 views
2

我想在加載數據時滾動到網格的末端。但代碼不起作用。請幫助滾動以結束網格UI-Grid Angular js

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

回答

4

您需要包括該模塊到您的js代碼:

ui.grid.cellNav

然後,這個卷軸是去工作:

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

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