how to make automatic paginator in p:dataGrid

2019-09-18 23:39发布

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?

2条回答
2楼-- · 2019-09-18 23:52

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

查看更多
混吃等死
3楼-- · 2019-09-19 00:05

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>
查看更多
登录 后发表回答