Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Table with expandable rows with 'lazy rendering' - angular material

I want to implement lazy loading on a material table with expandable rows. load the expanded data only after the row was clicked

example StackBlitz for Table with expandable rows.

In my project, from the main expanded table, I call another component inside the expanded-row space, that renders some data (inside the expanded row ).

like this:

  <!-- Expanded Content Column - The detail row is made up of this one column that spans across all columns -->
  <ng-container matColumnDef="expandedDetail">
    <td mat-cell *matCellDef="let element" [attr.colspan]="columnsToDisplay.length">
      <div class="example-element-detail"
           [@detailExpand]="element == expandedElement ? 'expanded' : 'collapsed'">
           <!--another component load  -->
           <p>
              <app-another-table [fromMainTable] = 'true'></app-another-table>
           </p>
      </div>
    </td>
  </ng-container>

The problem is that, by default, the expansion rows content will be initialized even when they are close. instead, I want to defer initialization until a specific row was clicked, and only the content related to his (the clicked row) expend space will load

like image 985
Jon Avatar asked Oct 31 '25 18:10

Jon


1 Answers

I wanted the same in my project. I simply wrapped the component inside a ng-container and added the *ngIf directive as shown below.

     <!-- Expanded Content Column - The detail row is made up of this one column that spans across all columns -->
  <ng-container matColumnDef="expandedDetail">
    <td mat-cell *matCellDef="let element" [attr.colspan]="columnsToDisplay.length">
      <div class="example-element-detail"
           [@detailExpand]="element == expandedElement ? 'expanded' : 'collapsed'">
        <ng-container *ngIf="expandedElement === element">
           <!--another component load  -->
           <p>
              <app-another-table [fromMainTable] = 'true'></app-another-table>
           </p>
        </ng-container>
      </div>
    </td>
  </ng-container>
like image 140
Jadamae77 Avatar answered Nov 02 '25 07:11

Jadamae77



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!