0

How can I access the collectionSize when using a filter

    <tr *ngFor="let t of types | generalfilter:filter 
          | slice:(page-1)*itemsPerPage:page*itemsPerPage">

in a way that number of filtered items is visible within the ngb-pagination ?

<ngb-pagination [collectionSize]="????"
aak
  • 61
  • 1
  • 1
  • 8
  • The solution is in: https://stackoverflow.com/questions/36073671/how-to-find-the-count-of-items-in-an-ngfor-after-the-pipes-have-been-applied – edu Apr 17 '19 at 19:38

1 Answers1

0

You will need to get this data from your backend. I do this by sending collectionSize in JSON format from backend to front end. So I do it this way in PHP:

$data['collectionSize'] = $num_rows; //$num_rows stands for the number of rows in DB
echo json_encode($data);

I subscribe to the Observable and assign the value to collectionSize in Angular, like so:

this.myService.getData()
.subscribe( response => { this.collectionSize = response.collectionSize; } );
Devner
  • 6,825
  • 11
  • 63
  • 104