Reputation: 33
I'm implementing an expandable ui grid. When a parent row is expanded, I want a row in the subgrid to be automatically selected based on the parent row's data.
How do I get a list of subgrid rows? Is there a way to find and select them with gridApi.selection
methods? I can set isSelected = true
if I have the row, and I can get a list of rows (that doesn't include any subgrid rows) with $scope.gridApi.grid.rows
, but I don't know how to get a list of subgrid rows.
$scope.fruits = [...];
$scope.colors = [...];
$scope.gridOptions = {
data: $scope.fruits,
enableRowSelection: true,
expandableRowTemplate: '<div ui-grid="row.entity.subGridOptions"></div>',
...
onRegisterApi: function (gridApi) {
$scope.gridApi = gridApi;
gridApi.expandable.on.rowExpandedStateChanged($scope, function (row) {
if (row.isExpanded) {
row.entity.subGridOptions = {
data: $scope.colors,
...
};
if (row.entity.color_id) {
// need help here
_.forEach(/*rows in subgrid*/, function(colorRow) {
if (colorRow.entity.id === row.entity.color_id) {
colorRow.isSelected = true;
}
});
}
}
});
}
};
Upvotes: 1
Views: 65