onRegisterApi
将您的第一个网格更新为如下内容:
onRegisterApi: function(gridApi) {
console.log('Loaded Grid API 1');
$scope.gridApi1 = gridApi;
$scope.mySelectedRows1 = gridApi.selection.getSelectedRows();
gridApi.selection.on.rowSelectionChanged($scope,function(row){
$scope.selectedRow = row.entity;
$scope.gridApi2.selection.selectRow($scope.selectedRow);
});
}
我正在绑定 rowSelectionChanged
事件第一个网格,因此,当用户选择一行时,它会被触发。我将选定的行存储在$scope.selectedRow
通过调用 API 选择第二个网格:selectRow
。请注意,您必须传递行实体才能获得正确的选择:
$scope.gridApi2.selection.selectRow($scope.selectedRow); <-- selectedRow is row entity
最后,你会得到这样的东西:
$scope.gridOptions1 = {
saveFocus: false,
saveScroll: true,
enableFiltering: true,
enableGridMenu: true,
onRegisterApi: function(gridApi) {
console.log('Loaded Grid API 1');
$scope.gridApi1 = gridApi;
gridApi.selection.on.rowSelectionChanged($scope,function(row){
$scope.gridApi2.selection.selectRow(row.entity);
});
}
};
$scope.gridOptions2 = {
saveFocus: false,
saveScroll: true,
enableFiltering: true,
enableGridMenu: true,
onRegisterApi: function(gridApi) {
console.log('Loaded Grid API 2');
$scope.gridApi2 = gridApi;
gridApi.selection.on.rowSelectionChanged($scope,function(row){
$scope.gridApi1.selection.selectRow(row.entity);
});
}
};