vendredi 25 février 2022

Select All checkboxes by default in nested mat table not working as expected

I have a nested mat table with expandable rows . Only the inner table has checkbox and by default all the checkbox has to be checked in all the nested tables . Here is the working stackblitz

https://stackblitz.com/edit/angular-nested-mat-table-triplenested-iavs62?file=app%2Ftable-expandable-rows-example.ts

    getProjectDetails(element: any) {
    console.log(element.Id);
    this.tableService.getInnerData(element.Id).subscribe((res) => {
      if (res.length == 0) {
        element['usersdataSource'] = new MatTableDataSource();
      } else {
        element['usersdataSource'] = new MatTableDataSource(res);
        this.userSelectionMap.set(
          element.Id,
          new SelectionModel<any>(true, [element['usersdataSource']])
        ); // provided datasource of the current inner table for default sselection
      }
    });
  }

I have provided the value of datasource for default selection while defining the selection model but it is not working as expected . I dont want to iterate over each table and do the selection as the data of inner table can be huge . What could be the best way to implement this ?




Aucun commentaire:

Enregistrer un commentaire