I made quite a lot of changes in the code you joined but main part is here with comments :
updateParentSelection(i, parentRow) {
if (this.cars[i].length > 0) { // if subselection not empty
if (this.parentSelection.indexOf(parentRow) === -1) { // if parent row not already selected
this.parentSelection = this.parentSelection.concat(parentRow); // add parent row to parent selection
}
} else { // if subselection empty
this.parentSelection.splice(this.parentSelection.indexOf(parentRow), 1).slice(0); // remove parent row from parent selection
this.parentSelection = [].concat(this.parentSelection.splice(this.parentSelection.indexOf(parentRow), 1).slice(0)); // trick to update the view
}
}
Don't hesitate if you have any questions.
See forked StackBlitz