3

I have a nested turbotable (p-table inside p-table) with checkboxes and expandable rows.

I would like to be able programmatically set certain checkboxes on, e.g. if a user selects a row in the nested table then the ckeckbox of the parent row should get selected also.

Check this StackBlitz

Antikhippe
  • 6,316
  • 2
  • 28
  • 43
mfabi
  • 1,038
  • 2
  • 10
  • 18

1 Answers1

2

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

Antikhippe
  • 6,316
  • 2
  • 28
  • 43