datatable 分页时发现,两个浏览器,其中一个添加数据后,另外那个翻到另一页,表格的内容变了,新增的数据有显示,但是总记录数没有更新,以致总页数不会更新。
找了一天,才找到解决办法。
- <p:dataTable var="recipe" value="#{recipeBean.model}"
- widgetVar="rtable" filterEvent="enter" rowKey="#{recipe.id}"
- paginator="true" rows="10" lazy="true" first="0"
- paginatorPosition="bottom" id="recipe_data_id"
- currentPageReportTemplate="(Total: {totalRecords}, Page: {currentPage}/{totalPages})"
- paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
- rowsPerPageTemplate="5,10,15,20,30,50"
- selection="#{recipeBean.selectedRecipes}">
- <p:ajax event="page"
- oncomplete="rtable.getPaginator().setTotalRecords(this.args.totalRecords)" />
<p:dataTable var="recipe" value="#{recipeBean.model}"
widgetVar="rtable" filterEvent="enter" rowKey="#{recipe.id}"
paginator="true" rows="10" lazy="true" first="0"
paginatorPosition="bottom" id="recipe_data_id"
currentPageReportTemplate="(Total: {totalRecords}, Page: {currentPage}/{totalPages})"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="5,10,15,20,30,50"
selection="#{recipeBean.selectedRecipes}">
<p:ajax event="page"
oncomplete="rtable.getPaginator().setTotalRecords(this.args.totalRecords)" />
解决办法就是添加ajax事件。
之前是,totalRecords的值不能更新,当页数有变化时,totalPages没有更新。
dataTable的ajax 事件列表:
参考: http://stackoverflow.com/questions/13867321/primefaces-ajax-event-for-lazy-datatable-list-updatepage - On pagination.
sort - When a column is sorted.
filter - On filtering.
rowSelect - When a row is being selected.
rowUnselect - When a row is being unselected.
rowEdit - When a row is edited.
rowEditCancel - When row edit is cancelled.
colResize - When a column is being selected.
toggleSelect - When header checkbox is toggled.
colReorder - When columns are reordered.
rowSelectRadio - Row selection with radio.
rowSelectCheckbox - Row selection with checkbox.
rowUnselectCheckbox - Row unselection with checkbox.
rowDblselect - Row selection with double click.
rowToggle - Row expand or collapse.
contextMenu - ContextMenu display.