suga
suga

Reputation: 155

How to customize the paginator from PrimeFaces datatable

I want to customize PrimeFace's data table pagination.

It is currently showing the page count at the bottom as: (1 of 5). I want to display the # of records in one page out of total number of records, such as: (1-10 of 50).

I have included my code below - but it isn't working. Could anyone please assist?

<p:dataTable id="tblStatusSearch" var="item" rowIndexVar="rowStatusSearch"      
    rows="10" paginator="true"  
    paginatorTemplate="{CurrentPageReport}  
    {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} "
    value="#{StatusAction.listEBeans}"

<f:facet name="footer"> 
    <h:outputText value="#{rowStatusSearch + 1} - 10 out of #{bondLocationStatusAction.itemCount}"/>
</f:facet>

Upvotes: 11

Views: 45483

Answers (3)

NickyPatel
NickyPatel

Reputation: 555

This will solve your purpose i think.

<p:dataTable id="datatable" var="car" value="#{myBean.cars}" paginator="true" rows="10"  
paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {CurrentPageReport}"
currentPageReportTemplate="{startRecord} - {endRecord} of {totalRecords}">
<p:column...../>
<p:column...../>
</p:datatable>    

In place of {CurrentPageReport} you will be able to see what you are looking for.

Upvotes: 3

Seitaridis
Seitaridis

Reputation: 4529

You can use a PrimeFaces currentPageReportTemplate for the CurrentPageReport like this:

<p:dataTable id="tblStatusSearch" var="item" paginator="true" rows="10"
    currentPageReportTemplate="Showing {startRecord}-{endRecord} out of {totalRecords}"
    paginatorTemplate="{CurrentPageReport}  
{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} "
    value="#{StatusAction.listEBeans}">

I confirm that it works in PrimeFaces 3.4.2. It is present in the users guide for PrimeFaces 3.0, so if you are using PrimeFaces 3.x it should work for you.

Upvotes: 25

Mehdi
Mehdi

Reputation: 4406

"please refer to the attached image" I think you have forgotten to attach image ;)

If you want to show the page size in your p:datatable you should declare two fields in your bean and hold the pageSize and first arguments values form load method inside them then you can show the page size with following paginatorTemplate:

paginatorTemplate=" {CurrentPageReport} #{yourBean.first + yourBean.pageSize} and rest of you template "

remember that EL works in paginatorTemplate property.

Upvotes: 0

Related Questions