如何行选择设置为新添加的行? [英] How to set row selection to newly added row?

查看:176
本文介绍了如何行选择设置为新添加的行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要设置选择为新添加的行。
当进入 $ scope.gridApi.selection.selectRow(NEWOBJECT)时,网格的列模型没有新行,因而无法选择它。
方法后 addRow 完成后,网格显示新行(和数据),但没有选择被做了。

I need to set selection to a newly added row. When $scope.gridApi.selection.selectRow(newObject) is entered, the grid's row model does not have the new row and thus can not select it. After method addRow is finished, the grid shows the new row (and the data) but no selection was made.

我的测试code:

$scope.addRow = function() {
    $scope.gridOptions.data.unshift({
        // my new data object
    });

    var newObject = $scope.gridOptions.data[0];
    $scope.gridApi.selection.selectRow(newObject);
};

我怎样才能实现这一行为?

How can I achieve this behavior?

有没有像在angularjs UI网我要听rowAdded事件?
在哪里有一个COM prehensive通过UI格触发事件的列表?

Is there an event like 'rowAdded' in angularjs ui-grid I have to listen to? Is there anywhere a comprehensive list of events fired by ui-grid?

感谢您的帮助!

推荐答案

您可以对行,列等事件侦听器。该文档是在这里 http://ui-grid.info/docs /#/api/ui.grid.class:Grid

You can event listeners on row, column and so on. The documentation is here http://ui-grid.info/docs/#/api/ui.grid.class:Grid

您可以在onRegisterApi添加数据听众像下面,

You can add the data listener in onRegisterApi like below,

onRegisterApi : function(gridApi)
            {
                if(!$scope.gridApi) 
                {
                    $scope.gridApi = gridApi; 
                    $scope.gridApi.grid.registerDataChangeCallback(function(data)
                    {
                      $scope.gridApi.selection.selectRow($scope.gridOptions.data[0]);
                    }, [uiGridConstants.dataChange.ROW]);
                }
            }

和选择您要选择的任何行。

and select any row you want to select.

下面是一个工作plnkr。 http://plnkr.co/edit/NjnMb65w86L0bKmkkJp0?p=$p$pview

Here is a working plnkr. http://plnkr.co/edit/NjnMb65w86L0bKmkkJp0?p=preview

这篇关于如何行选择设置为新添加的行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆