0

I have a primefaces datatable with a paginator template in selection mode. If I am at first page, by exemple, and I select in my bean a record that is in page 4 of paginatortemplate datatable, how can I move programmatically to the page 4 to view the selected row?

xhtml:

<p:dataTable id="tablaVista" 
   var="u"
   value="#{mtoArticulosBean.listaGeneral}"
   emptyMessage="#{msgs.NoHayRegistros}"
   paginator="true" rows="12"  
   paginatorTemplate="{CurrentPageReport}  {FirstPageLink}   PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} "  
   selection="#{mtoArticulosBean.registroSel}"
   selectionMode="single" 
   rowKey="#{u.codArticulo}">
   .....
</p:datatable

mtoArticulosBean:

....

setRegistroSel(getListaGeneral().get(42));

....

The user still sees the page 1 although the selected record is on page 4

Thanks in advance

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Jose A. Gam
  • 3
  • 1
  • 3

1 Answers1

1

You can (should) use the 'first' attribute of the datatable. When setting the selection, calculate on which page it is (record number / page size) and makecthat available in a bean.

In your xhtml you can then do

<p:datatable first="#{myBean.first}"....    

(See also Primefaces: set page on datatable)

Community
  • 1
  • 1
Kukeltje
  • 12,223
  • 4
  • 24
  • 47