如何将行选择设置为新添加的行? [英] How to set row selection to newly added row?
问题描述
我需要将选择设置为新添加的行.当输入$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屋!