0

I have a found multiple scenarios where either 100s of rows of data need to be loaded or 10s of rows need to be loaded but they all have many components inside. Is there a way to dynamically load only the rows being viewed in the scroll viewport?

Example of a case where there is a heavy component that needs to be loaded for multiple columns in each row:

<table mat-table matSort [dataSource]="tableDataSource" #resultsTable class="mat-elevation-z1">

    <ng-container *ngFor="let col of columnsToDisplay;" matColumnDef="{{col}}">
        <th mat-header-cell *matHeaderCellDef>{{ col }}</th>
        <td mat-cell *matCellDef="let entry; let rowNumber = index">
            <app-autocomplete
                    #autocompleteCell
                    [id]="'cell-'+rowNumber+'-'+col" *ngIf="col!='controls'"
                    [type]="col"
                    [data]="entry[col]"
                    [disabled]="col=='approvedBy' || entry.exported"
                    (keydown.arrowdown)="downCell(rowNumber,col)"
                    (keydown.arrowup)="upCell(rowNumber,col)"
                    [formatting]="entry.entryType+''"
                    (input)="textChange(rowNumber,col)"
                    (dataChange)="updateAfterAutofill($event,rowNumber,col)">
            </app-autocomplete>
            <button mat-icon-button *ngIf="col=='controls'" color="warn" (click)="deleteRow(entry.id,true)" class="control" matTooltip="Delete row">
                    <mat-icon>delete</mat-icon>
                </button>
        </td>
        <td mat-footer-cell *matFooterCellDef>{{getColumnTotal(col)}}</td>
    </ng-container>
    
    <tr mat-header-row *matHeaderRowDef="columnsToDisplay; sticky: true"></tr>
    <tr mat-row *matRowDef="let myRowData; columns: columnsToDisplay"
        (contextmenu)="contextMenu($event, myRowData)"
        [matTooltip]="myRowData.exported?'Can\'t edit a row that has already been exported':''"
        matTooltipPosition="above">
    </tr>
    <tr mat-footer-row *matFooterRowDef="columnsToDisplay sticky: true" matTooltip="Total Hours per Day"></tr>
</table>
1
  • yes, you'd use pagination and LIMIT queries on the backend. If you wanted to trigger load on scroll, you'd basically want to use a fixed number of entries and load new, remove old... (a sort of rolling cache... else you risk bogging down the browser with too much data) Search for "infinite scroll"... if implemented correctly it won't actually keep loading and loading data... maybe see this thread: stackoverflow.com/questions/57142883/… Commented 21 hours ago

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.