components icon indicating copy to clipboard operation
components copied to clipboard

[Paginator] Add jump-to-page functionality

Open dushkostanoeski opened this issue 6 years ago • 29 comments

Bug, feature request, or proposal:

Feature request

What is the expected behavior?

To be able to jump to a specific page using a dropdown populated with page numbers. The dropdown should be next in line after the Items per page dropdown, so you can choose the page size and then the page number you want to go to.

Don't know if the following part is smart, but in use cases where the page number is large, a step input can be implemented. If the total number of pages is 500, and the step is 5, the Page number dropdown would hold only pages 1, 5, 10, 15, 20 .... so the user can get to the desired page in as little scrolling and as few clicks as possible.

What is the current behavior?

To get to a specific page you have to go page by page

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

In my case, I have a 100 item per page list, that has 3500 total items sorted by date and the users land at the last page. If the users wants to check the items that were added at the beginning of the year, they know that they should be looking at items from 1 to at least 300, so that is 32 clicks to get to the desired items. As the total page count gets bigger, the harder it is to get to the last pages (first pages in my case).

dushkostanoeski avatar Oct 07 '17 08:10 dushkostanoeski

Maybe something like this will help in the mean time

https://stackblitz.com/edit/material2-beta12-fpf2ka?file=app%2Fapp.component.ts

willshowell avatar Oct 09 '17 16:10 willshowell

I have a working component that wraps around the paginator, adds the dropdown and all the events are bound to the same function so you don't need to have separate event handlers.

A paginator component should let you get to a specific page easily. I'd make a PR if the idea is considered acceptable.

dushkostanoeski avatar Oct 09 '17 18:10 dushkostanoeski

@andrewseguin will this get in on the next beta?

dushkostanoeski avatar Oct 21 '17 07:10 dushkostanoeski

@dushkostanoeski We haven't started work on something like this, especially since its out of the spec and we'd have to really consider how the UX would play out here

andrewseguin avatar Oct 24 '17 22:10 andrewseguin

button for firstPage and lastPage is also needed, should I create a new ticket? Couldn't find a ticket until now for such functionality.

Chris2011 avatar Jan 04 '18 13:01 Chris2011

I think it's possible using the existing API. You can try like this...

 this.paginator.pageIndex = pageNumber, // number of the page you want to jump.
 this.paginator.page.next({      
      pageIndex: pageNumber,
      pageSize: this.paginator.pageSize,
      length: this.paginator.length
    });

where this.paginator is

@Input()
paginator: MatPaginator;

For jumping to a specific page you can add an input box or select box and execute that piece of code and for jumping to previous or last page two button could be added which could use that too.

Asad-Islam avatar Jan 18 '18 11:01 Asad-Islam

Extending the current paginator isn't a problem, the thing is that a paginator should have a jump to page functionality.

dushkostanoeski avatar Jan 19 '18 07:01 dushkostanoeski

@dushkostanoeski yes you're right. It would've been a useful functionality.

Asad-Islam avatar Jan 19 '18 08:01 Asad-Islam

@andrewseguin I can make a PR about this, if that's OK

dushkostanoeski avatar Mar 05 '18 19:03 dushkostanoeski

You're welcome to open a PR but it may be worth discussing what the UX would look like. Do you have suggestions on how the UI would appear?

andrewseguin avatar Mar 06 '18 22:03 andrewseguin

The field would be optional and I was thinking of adding it after the Items per page field. The label would say Jump to page: followed by a dropdown populated with the page numbers. That way the user can choose the page size and then jump to the desired page.

dushkostanoeski avatar Mar 06 '18 23:03 dushkostanoeski

What would the select options text be? Page numbers or item ranges? Configurable via MatPaginatorIntl?

willshowell avatar Mar 07 '18 15:03 willshowell

The Jump to page label makes you think of page numbers, but being able to choose between item ranges and page numbers, or even both, something like Jump to page: 2 (11 - 20) is even better.

Should the label change depending on what the dropdown is populated with?

dushkostanoeski avatar Mar 07 '18 17:03 dushkostanoeski

Can it look the same like in https://github.com/daniel-nagy/md-data-table

AntonisFK avatar Mar 09 '18 18:03 AntonisFK

That's pretty much the idea

dushkostanoeski avatar Mar 09 '18 18:03 dushkostanoeski

How about converting the .mat-paginator-range-label to a mat-select so a user can choose the range directly.

Would look like this: image

mzernetsch avatar Jun 26 '18 08:06 mzernetsch

hii

https://stackoverflow.com/questions/51542796/table-angular-material-pagination-does-not-work-as-expected

was this solved at all? can some check this thread related to this too ?

throne1986 avatar Jul 26 '18 16:07 throne1986

+1 this would be super useful

alex-osman avatar Aug 15 '18 16:08 alex-osman

+1

piyushgupta1 avatar Oct 26 '18 17:10 piyushgupta1

How about a UI like something like what @shlomiassaf has in his table demos? It feels very natural to put the current page index between the next and prev buttons.

image

sumigoma avatar Nov 05 '18 19:11 sumigoma

How about a UI like something like what @shlomiassaf has in his table demos? It feels very natural to put the current page index between the next and prev buttons.

image

Could please provide a link to this demo? Thank you!

bastian-f avatar Feb 20 '19 10:02 bastian-f

@bastian-f https://shlomiassaf.github.io/table-demo/table-demo#/extensions/pagination

parys avatar Mar 19 '19 11:03 parys

Any chances this gets implemented this year? Doesn't look like the suggestions took traction.

azamanaza avatar May 12 '20 03:05 azamanaza

I have created a mat-paginator-goto component over mat-paginator, this works same as original mat-paginator but also has option of goTo/jumpTo specific page.

The list of available pages for goTo have been calculated based on length and pageSize.

To Integrate in your angular/material project follow below steps

Step 1: Goto mat-paginator-with-goto (Stackblitz)

Step 2: Copy folder(mat-paginator-goto) and paste into you project

Step 3: Import in your module

import { MatPaginatorGotoComponent } from './mat-paginator-goto/mat-paginator-goto.component';

@NgModule({
  declarations: [ ...MatPaginatorGotoComponent ],
})

Step 4: Use it same as original mat-paginator

<mat-paginator-goto [length]="100" [pageSize]="10" [pageSizeOptions]="[5, 10, 25, 100]"
		(page)="paginationChange($event)"></mat-paginator-goto>

Note: Update import paths and styles accordingly

sameerthekhans avatar May 27 '20 08:05 sameerthekhans

We may want to accommodate a design like the one mentioned in https://github.com/angular/components/issues/22361#issue-843300077.

112833501-df95b280-90a7-11eb-95b8-12c503039e9e

crisbeto avatar Mar 29 '21 15:03 crisbeto

We may want to accommodate a design like the one mentioned in #22361 (comment).

112833501-df95b280-90a7-11eb-95b8-12c503039e9e

I liked that design

hardikhari96 avatar Jan 04 '22 10:01 hardikhari96

Great, but in this design, 1 and 100 is the same that first and last page. We don't need the two sign at the end. The number is better cause we have the gain of the information.

We loose the gain of the proximity of the two arrows two (less moove of the mouse). It will be great to have a reflexion of the good practice to have the less click to go to a page (like a page 75 and a page 25 ?

Something like this

image

image

image

image

Doyalle avatar Mar 19 '22 17:03 Doyalle

How about converting the .mat-paginator-range-label to a mat-select so a user can choose the range directly.

Would look like this: image

Hi, did you have a working example of this? Thank you.

Khelthos avatar Jun 23 '22 09:06 Khelthos

So, it's been 5 (FIVE) years? Are you going to make it or now? If not, just say so.

alvipeo avatar Oct 15 '22 05:10 alvipeo