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

dir-paginate: Count results on that page #450

Open
connor-simpson opened this issue May 5, 2017 · 1 comment
Open

dir-paginate: Count results on that page #450

connor-simpson opened this issue May 5, 2017 · 1 comment

Comments

@connor-simpson
Copy link

When using dirPagination is there a way to count the results that are currently shown on the page and also get the complete number of results.

I know I can use array.length to get the complete number of results, but I can't do anything to get the total results on that page other than using the property value of the total items per page which doesn't always match the results on that page.

If I've not explained it enough I'm trying to do a Displaying 1-20 of 150 but then there is only 1-7 of 7. I can't do that.

Bare in mind I've seen the documentation of the dir-pagination-controls but it doesn't work with the layout of my page.

Code:
<tr dir-paginate="lead in filteredLeads = (Leads | filter: leadSearchKeyword | filter: leadsFilter | filter: dateFilter) | itemsPerPage: 20" ng-class="(lead.refundStatus == 'none' ? 'active' :(lead.refundStatus == 0 ? 'pending' : (lead.refundStatus == 1 ? 'declined' : 'active')))" current-page="currentPage">1</tr>

@dev-dan
Copy link

dev-dan commented Jun 16, 2017

You could accomplish this with some simple math with the variables you already have. As this is not a code issue and the author no longer maintains this software, if this solution works for you please close this issue so they are not burdened with open issues. You should find this an acceptable starting point, although will need to implement it as needed to work in your view:

Let's say say resultsOnPage is the var you want to store the results in.
Multiply the itemsPerPage by currentPage, and check if the array.length is more than or equal to this. If it is, then resultsOnPage would be equal to itemsPerPage. If it's less than it, subtract that number from array.length, and that will be the remaining number on that last page (or first page if the total results don't populate a whole page).

if(array.length >= currentPage*itemsPerPage){
  resultsOnPage = itemsPerPage;
} else {
  resultsOnPage = array.length-itemsPerPage;
}

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

No branches or pull requests

2 participants