Components: [Paginator] Ability to manually update hasNextPage() return value

Created on 15 Dec 2017  路  7Comments  路  Source: angular/components

Bug, feature request, or proposal:

Feature request

What is the expected behavior?

Return value of hasNextPage() (or hasPreviousPage()) method can be updated manually by a property outside of pageSize and pageIndex.

What is the current behavior?

Calculates return value based on pageSize and pageIndex

What is the use-case or motivation for changing an existing behavior?

In the event when the pageSize/length passed is not an accurate representation of the true length but an estimated length (when data is sent via the server). In this case, useful to be able to determine hasNextPage() method based on whether or not the server determines a next page exists. Otherwise, paginator will either allow nextPage events to fire when an empty query is returned or disallow pagination when more data can be queried.

P3 materiapaginator feature

Most helpful comment

+1
For me data size is always unknown from server, we only know if a next page exists with a token. When a page is loading but we'd like to disable "next" button before getting the response.

All 7 comments

Are you overriding the label to inform the users that there are more items? If they see "91-100 of 100", what do they expect the next page button to do?

I suspect that you would want to display something like "91-100 of 100+", and if you are overriding the range label anyways, you can set the length to be any arbitrary high value that could exist on the server so that the buttons react correctly.

@andrewseguin Currently, I just keep the range label as is not to add any additional complexity and adjust the length property dependent upon the response from the server. But if I were to override the label manually, then I'd likely use the method you suggested.

@andrewseguin Except now that I look at the MatPagniatorIntl service, I'm not sure if that's a viable method because there would be no way to properly extend getRangeLabel without the length property? If an arbitrarily long length is passed, then the extended class wouldn't be able to include the length property. You could have a startIndex and endIndex visible, but there wouldn't be a way for the user to know what the total/estimated total length is.

Code excerpt below as reference:

getRangeLabel = (page: number, pageSize: number, length: number) => {
  if (length == 0 || pageSize == 0) { return `0 of ${length}`; }

  length = Math.max(length, 0);

  const startIndex = page * pageSize;

  // If the start index exceeds the list length, do not try and fix the end index to the end.
  const endIndex = startIndex < length ?
    Math.min(startIndex + pageSize, length) :
    startIndex + pageSize;

  return `${startIndex + 1} - ${endIndex} of ${length}`;
}

Valid point, I'll try to consider some more about how we can develop the interface for this use case

I encountered a similar use case that the data size is unknown and I would like to disable "Next Page" when I get an empty result from server.
Look forward to this feature!

+1
For me data size is always unknown from server, we only know if a next page exists with a token. When a page is loading but we'd like to disable "next" button before getting the response.

I think that many of us requesting this feature are using GraphQL, where in most cases it does not return a total count, because it can be extremely inefficient to do so. Instead of providing a length, allowing an input to bind to a value for hasNextPage or hasCurrentPage would be fantastic.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alanpurple picture alanpurple  路  3Comments

kara picture kara  路  3Comments

crutchcorn picture crutchcorn  路  3Comments

constantinlucian picture constantinlucian  路  3Comments

vitaly-t picture vitaly-t  路  3Comments