我的团队一直在尝试以下方面:
$scope.addTest = function () { var TestRow = { "name": "xx","description": "xx","subjectId": 15 }; $scope.gridOptions.selectAll() var testRowLength = $scope.gridData.push(TestRow); $scope.gridOptions.selectItem(testRowLength - 1,true); }
但是最后一个selectItem没有正确执行select.所以我们尝试了以下方法:
$scope.$apply(function () { $scope.gridData.push(TestRow); $scope.gridOptions.selectItem(testRowLength - 1,true); });
现在我们收到一条错误消息:
Error: $apply already in progress
这个问题是在ng-grid博客上发布的一个问题,但它刚刚发布,我们需要尽快帮助解决这个问题.我希望有人可以就我们的方式向我们提出建议
解决方法
您过早选择该行,请改用ngGridEventData事件.我将新行推送到网格的开头,因此滚动更容易:
$scope.add = function(){ var emptyContact = Utilities.newContact(); var e = $scope.$on('ngGridEventData',function() { $scope.contactsGridOptions.selectItem(0,true); window.scrollTo(0,0); e(); }); $scope.contacts.unshift(emptyContact); };
有关滚动的更多信息:How do I scroll an ngGrid to show the current selection?
相关的ng-grid问题:https://github.com/angular-ui/ng-grid/issues/354