Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need new methods in "paginationApi" while using <pagination-template> #258

Closed
ksatyaprakash opened this issue Jun 18, 2018 · 2 comments
Closed

Comments

@ksatyaprakash
Copy link

Hi Team,

Is it possble to provide new methods (pApi.getTotalItems(), pApi.getItemsPerPage()) from paginationApi.

Scenario (using angular 5):

  • Sample screenshot
    image
    image
    image (with filterBy)

  • Using with data filter, inside "pagination-template", to display "Displaying 1 - 12 of 63" along with number of pages

  • Sample Code:
    <tr *ngFor="let row of dataCollection | filterBy: searchText | orderBy:{ property: sortBy, direction: reverse } | paginate: { itemsPerPage: itemsPerPage, currentPage: p }; let i = index" class="cald_tr_cells">
    .....
    <pagination-template #pApi="paginationApi" [id]="custom" (pageChange)="p = $event"><div class="range-label" style="padding-top: 5px;padding-left: 5px;">Displaying {{(( p > 1 ? p : 1 ) - 1) * pApi.getItemsPerPage() + 1}} - {{(( ( p > 1 ? p : 1 ) - 1) * pApi.getItemsPerPage()) + pApi.getItemsPerPage() > pApi.getTotalItems() ? pApi.getTotalItems() : ((( p > 1 ? p : 1 ) - 1) * pApi.getItemsPerPage()) + pApi.getItemsPerPage()}} of {{ pApi.getTotalItems() }}</div> <!-- some code to design pages --></pagination-template>

Regards,
Satya

@michaelbromley
Copy link
Owner

Hi Satya,

Thanks for the suggestions. I wonder whether the proposed pApi.getItemsPerPage() is really needed, since this information is readily available since it is defined by the user config. If the motivation for adding this API so that the itemsPerPage value does not need to be explicitly passed down to the custom template?

Regarding the pApi.getTotalItems() method, this is certainly something that is not easily achievable currently in the case of things like a filter pipe which changes the size of the set (see #166, #99).

In the case of an array of items which is being filtered by some custom pipe prior to pagination, the total length is already being stored internally in the PaginationInstance (see here) so this could be exposed in the PaginationControlsDirective with a method like:

getTotalItems(): number {
  return this.service.getInstance(this.id).totalItems
}

BTW, If you feel inclined to submit a pull request for this, let me know. Otherwise I will mark it to add in a future update.

@ksatyaprakash
Copy link
Author

Thanks Michael,

Yes, we don't need pApi.getItemsPerPage(), we already know what is the page size.

Please provide this feature pApi.getTotalItems() in you next release.

Thanks & Regards,
Satya

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants