我们如何添加一行到NG-网格,然后选择该行?网格、NG

2023-09-14 00:13:01 作者:小鹿乱蹦

我的团队一直在尝试以下内容:

My team have been trying the following:

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

但是最后选择信息不正确地做一个选择。因此,我们尝试了以下内容:

However the last selectItem does not correctly do a select. So we tried the following:

        $scope.$apply(function () {
            $scope.gridData.push(TestRow);
            $scope.gridOptions.selectItem(testRowLength - 1, true);
        });

现在,我们得到一个错误消息说:

Now we get an error message saying:

Error: $apply already in progress

此问题是张贴在NG网博客一个问题,但它只是刚刚发表,我们需要尽快在这方面帮助。我希望有人可以给我们的建议我们如何能够

This problem is posted as an issue on the ng-grid blog but it's only just been posted and we need help with this as soon as possible. I hope someone can give us advice on how we can

推荐答案

您离开的太快选择行,使用 ngGridEventData 事件来代替。我推新行到网格的开始,所以滚动变得更轻松:

You're selecting the row too soon, use ngGridEventData event instead. I push new rows to the beginning of the grid, so scrolling is a little easier:

$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我做一个滚动到ngGrid显示当前选择?

相关NG-电网的问题: https://github.com/angular- UI / NG网/问题/ 354

Related ng-grid issue: https://github.com/angular-ui/ng-grid/issues/354