PrimeFaces 3.2 DataTable "jump to page" paginator template? - jsf

According to the official PrimeFaces 3.2 documentation, the paginator template can be a combination of the following predefined paginator templates:
{FirstPageLink}
{LastPageLink}
{PreviousPageLink}
{NextPageLink}
{PageLinks}
{CurrentPageReport}
{RowsPerPageDropDown}
This is fine for small data sets, but it's extremely hard to navigate thru the pages if the data set is huge: imagine you have a few thousands (or even more) of pages, you're at the very first start, page No. 1, and you want to jump directly to page No. 813, and then -- to No. 499). So:
Is there a way to enhance the existing templates set for the paginator in PrimeFaces 3.2 DataTable, e.g. adding a custom template?
If not, ... is there a way (I assume it as a potential hack) affect the data table navigation like in the scenario I described above?
Your help would be really appreciated.
Thanks in advance.

There is a paginator option {JumpToPageDropdown} you can use to select the page from the dropdown. I don't think it is documented.

Related

How to customize primefaces page links?

In our application we were loaded 20000 records in the primefaces data table but we faced some performance issue. so we planned to load the data page by page for that we sent start and end page number to back end and we got minimal records. On every page change we hit the Db and loads the data in data table.
First time i have sent 1 and 100, i got 100 records and total matched record count is 1800. i have set the list value in datable my page size is 50 and it shows the 2 page links in the data table.
i want to set the page links dynamically based on the total matched record. but in primefaces it shows based on the datatable list size. how can i set the page links dynamically.
My expected output:
Wanted:
PF's paginator.
Example from website:
<p:dataTable var="car" value="#{dtPaginatorView.cars}" rows="10"
paginator="true"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="5,10,15">
Not wanted:
Most JSF tags (not HTML, of course) support an attribute styleClass="foo" which can be used to attach a class="foo" attribute the resulting HTML tag.
Maybe that is what you need? Sorry, I have never attempted to modify these links (using PF6.0 CE).

Primefaces datatable and current page not working

I'm using Prime Faces 6.0.
I've a datatable with a LazyDataModel. The user can change the page with the built-in paginator.
When the user switch from the first page, to the second I need to know the currentPage, and I need it in the client part.
This is the code of the datatable
<p:dataTable
id="listingsTable"
value="#{listingsLazyDataModel}"
var="actualAd"
paginator="true"
rows="#{applicationScopedBean.advertisingsPaginationSize}"
lazy="true"
paginatorTemplate="{FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
rowsPerPageTemplate="10,20,30"
paginatorPosition="bottom"
widgetVar="listingsTableDesktop"
first="#{searchAdvertisingModel.currentPage*applicationScopedBean.advertisingsPaginationSize}">
...
...
<p:ajax event="page" listener="#{listingsController.pageChanged}" oncomplete="pageChangedOnDetails(PF('listingsTableDesktop'))" />
...
---
</p:dataTable>
and this is the js code
function pageChangedOnDetails(listingsTableDesktop){
console.log(listingsTableDesktop.paginator.getCurrentPage());
}
The problem is that the getCurrentPage() method returns the previous page. Not the actual one. Just for information, the page is base 0. So the first page is the page 0.
Example of the actual behaviour vs expected one
User land in the page and see the first page.
User switch to the second page. getCurrentPage -> 0 WRONG expected 1
User switch to the third page. getCurrectPage -> 1 WRONG expected 2
User switch to the first page. getCurrentPage -> 2 WRONG expected 0
In which way can I solve this?
Thank you
The base is 0 but your event function is running way to soon it seems.
Try running your function else where other then event="page".
I mean by this, when your page is a 1 (default) and you click for example on page 3, it outputs a 0 (0+1= page 1) and ONLY AFTER THAT it goes to page 3. If you click on page 6 now, it outputs a 2 (2+1= page 3) and ONLY AFTER that it goes to page 6.
This happen even with oncomplete instead of onclick. Hope it helped.
This problem was a bug found in PF 6.0 and 6.1, but with the current version (6.2) this problem is solved

Is Primefaces DataGrid able for lazy loading?

I created some development startup code with the generjee online tool.
Have selected DataGrid for the data list style and have choosen lazy loading for some entities.
Now I'm wondering if Primefaces DataGrid is really able to lazily load the data? In the Primefaces DataGrid Showcase there is nothing about lazy loading. Is this feature supported? I'm new to Faces.
Yes PrimeFaces can do lazy loading, for this, you have to put the attributes.
Here is an example of a lazy DataGrid :
<p:dataGrid var="car" value="#{carBean.cars}" columns="3" rows="12"
paginator="true" lazy="true">
...
</p:dataGrid>
value="#{carBean.cars}" : list of backing Bean
lazy="true" : allow lazy loading
rows="12" : Number of items to load in lazy
paginator="true" : Activate pagination

Primefaces : lazy loaded datatable's paginator buttons not showing

i have previously used datatable pagination and it worked as a charm. This time i needed to use the lazy loaded pagination and its showing the first page and there are no paginator buttons. I have tried a lot of things but it just isnt showing the paginator buttons. if i change the number of rows, it works i.e the number of rows on tht page changed but the paginaotor buttons are not showing. if i inspect the datatable in chrome, it shows thr is a div for the paginator bottom
<div xmlns="http://www.w3.org/1999/xhtml" id="j_idt7:contentTable_paginatorbottom" class="ui-paginator ui-paginator-bottom ui-widget-header ui-corner-bl ui-corner-br"></div>
this is my datatable
<p:dataTable id="contentTable" value="#{chatroomBean.lazyLoadedChatroomBeans}"
var="chatroom" paginator="true" paginatorPosition="bottom" rows="10" lazy="true"
paginatorTemplate=" {PreviousPageLink} {CurrentPageReport} {NextPageLink} "
rendered="#{chatroomBean.chatroomSearchText!=null}">
i am using jsf2, primefaces 2.2.1 and apache tomcat 6.
any help idea will be much appreciated. thanks
regards
khizar
I think you've run into this bug.
From the linked-to forum discussion:
Here is a workaround. Copy the
following lines in your load-Methode,
to update the pagination:
RequestContext context =
RequestContext.getCurrentInstance();
if(context!=null)context.addCallbackParam("totalRecords",
i);
The Variable i stand for the result of
the projections query.
its late but i just saw this question n remembered tht i had solved the prob so i thot i shud leave an answer here just in case sum1 else runs into it. the problem was tht the theme i was using cudnt find the images for the buttons, due to sum reason i cant remember now, i was not using the jar for the theme, i just added the theme.css to my project and it started working ... only problem was the links to images in the theme.css were like
url("#{resource['primefaces-glass-x:images/default.png']}") 0 0
changed them to this
url(images/default.png) 0 0
n it works like a charm ...
another solution (n probably the better one) wud be to add the jar for the theme in classpath and add the theme to web.xml but everyone probably knows tht ... :)
Regards,
khizar

jsf primefaces - two p:dataTable pagination questions

I'm using a p:dataTable with pagination like so:
<p:dataTable var="user" value="#{userBean.users}"
paginator="true" rows="20"
paginatorTemplate="{PageLinks}" >
Two questions:
1) Is there a way to tell it to not show the page numbers when there's only one page?
2) When I click from page 1 to page 2, the whole web page refreshes. On the PrimeFaces demo the pagination flips pages with an AJAX-style update. What have I done wrong that the web page is refreshing?
Any help is greatly appreciated, thanks!
rob
Try the following for question 1:
paginatorAlwaysVisible="false"
From the primefaces javadoc:
paginatorAlwaysVisible: Defines if paginator should be hidden when number of rows displayed is less than paginator rowsPerPage option.

Resources