components icon indicating copy to clipboard operation
components copied to clipboard

When we put the condition in Mat-paginator, pagination is not working.

Open mdhvfrnd opened this issue 8 years ago • 9 comments

Hi when we put the condition still this is not working.

<mat-paginator *ngIf="allItems ?.length > 0" #paginator [pageSize]="50" [pageSizeOptions]="[1,2,4,20, 40,100,150,200]">

If we remove the *ngIf="allItems ?.length > 0", this is working.

mdhvfrnd avatar Mar 19 '18 09:03 mdhvfrnd

Make a stackblitz reproduction of the problem.

fxck avatar Mar 19 '18 10:03 fxck

If we put any condition it wont work.

There is no condition in below code.So it will work. <mat-paginator #paginator [pageSize]="50" [pageSizeOptions]="[1,2,4,20, 40,100,150,200]">

when we put the condition, this is not working.

<mat-paginator *ngIf="allItems ?.length > 0" #paginator [pageSize]="50" [pageSizeOptions]="[1,2,4,20, 40,100,150,200]">

mdhvfrnd avatar Mar 19 '18 10:03 mdhvfrnd

What if you encapsule the mat-paginator into a div with ngIf ? To workaround for the moment.

WizardPC avatar Mar 19 '18 20:03 WizardPC

After if condition, now sorting and pagination both are not working. If i will remove if condition both will work. But how i will add the if condition.

mdhvfrnd avatar Mar 20 '18 05:03 mdhvfrnd

<div *ngIf="allItems ?.length > 0">
  <mat-table class="markstable" #table [dataSource]="dataSource" matSort>
    <ng-container matColumnDef="admissionno">
      <mat-header-cell class="markstable" *matHeaderCellDef mat-sort-header>
        <div class="tableheader">Admission No</div>
      </mat-header-cell>
      <mat-cell class="markscell" *matCellDef="let feePayment">
        {{feePayment.admissionno}}         
         </mat-cell>
    </ng-container>
	<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
    <mat-row *matRowDef="let row; columns: displayedColumns;"></mat-row>
  </mat-table>
  <mat-paginator  #paginator [pageSize]="50" [pageSizeOptions]="[2,20, 40,100,150,200]">
  </mat-paginator>
</div> 

mdhvfrnd avatar Mar 20 '18 05:03 mdhvfrnd

Closing this issue as it does not follow the issue template. Please file a new issue that follows the template, which gives the team the information needed to investigate

josephperrott avatar Mar 26 '18 15:03 josephperrott

I suspect you are trying to get the paginator using ViewChild, which won't work since the if statement will block it from getting the child.

andrewseguin avatar Mar 27 '18 16:03 andrewseguin

Put pagination outside of NgIF and apply condition on paginator using following

...

gauravdeshmukh612 avatar Feb 07 '19 04:02 gauravdeshmukh612

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.