I would like to make my <p:dataGrid>
pagination automatic. Without using the next button, move to the next page in few seconds.
<p:dataGrid id="cars" var="of" value="#{infoBaseOfVals.listinfoBaseOf}"
columns="2" rows="4" layout="grid" paginator="true" cellpadding="10"
cellspacing="20px" scrolling="false" responsive="true" type="unordered" itemType="none"
paginatorTemplate="Nombre OFs : #infoBaseOfVals.listinfoBaseOf.size()} OFs {CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="2,4,8,16,24,32,40,48,56,64,72,80">
How can I achieve this?
For recent versions of PrimeFaces (at least 6.0, but maybe also some before) You can achieve that with a little javascript. Set the widgetVar attribute to your dataGrid and add something like this:
var myVar = setInterval(myTimer, 5000);
myDataGridPaginator = PF('myDatagridWidgetVar').getPaginator();
function myTimer() {
myDataGridPaginator().setPage(myDataGridPaginator.cfg.page + 1);
}
For older PrimeFaces version (if this does not work) see the other answer
For older versions of PrimeFaces it works with javaScript
this is the script
var myVar = setInterval(myTimer, 5000);
function myTimer() {
var myvar1 = myDataGrid.cfg.paginator.page;
var myvar2 = myDataGrid.cfg.paginator.pageCount - 1;
if(myvar1 == myvar2)
myDataGrid.paginator.setPage(0) ;
myDataGrid.paginator.setPage(myDataGrid.cfg.paginator.page + 1);
}
<p:dataGrid widgetVar="myDataGrid" id="cars" var="of" value="#infoBaseOfVals.listinfoBaseOf}"
columns="2" rows="4"paginator="true" responsive="true" itemType="none"
paginatorTemplate="Nombre OFs : #{infoBaseOfVals.listinfoBaseOf.size()} OFs {CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="2,4,8,16,24" >
<h:outputText value="#{of.of_id}" />
</p:dataGrid>