bashirudeen ahmad
bashirudeen ahmad

Reputation: 213

how to display records per page in angular 4 ngx pagination

I have installed ngx pagination in angular 4. Everything works fine. I want to display records per page. ie. (Showing: 1 - 10 / 25 ). I have tried but i did not get any solution. Could you please help me on this. Thanks in advance.

Upvotes: 2

Views: 3214

Answers (2)

Bhrungarajni
Bhrungarajni

Reputation: 2535

i have worked in this way and it helped,

 public setPageNumbers(pageNo,pageSize) {
    this.startValue = (pageNo * pageSize) - (pageSize -1)
    this.lastValue = this.agentParms.pageNo * this.agentParms.pageSize;
    this.lastValue = this.lastValue > this.agentTotal ? this.agentTotal: this.lastValue;
  }

so here i am multiplying, with current page number and page size, and subtracting with the current page size, so i get the first value, and to obtain last value, checking with page no. and page size, and displaying that as last value.. If the last value is greater than the total count, then the total count is taken as the last value.

Hope this helps.

Upvotes: 1

Ankita Gupta
Ankita Gupta

Reputation: 583

You can use PaginatePipe at the end of an NgFor expression.And you can pass number of records you want to display as config option.

<element *ngFor="let item of collection | paginate: { itemsPerPage: pageSize,
                                                  currentPage: p,}">...</element>

Upvotes: 0

Related Questions