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

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

问题描述

我需要将选择设置为新添加的行.当输入$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.

我的测试代码:

$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-grid 中是否有像rowAdded"这样的事件我必须听?是否有 ui-grid 触发的完整事件列表?

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:网格

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=preview

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

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

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