0

The following code does not update the current datatable row count correctly after applying filtering. Sometimes I have to hit the enter key twice in the filter input box after typing the text so the count is updated correctly. And sometimes it just works after I type the text and without pressing the enter key. Sometimes I can also just type the enter key once and the count is updated correctly. I don't understand why I get this different behavior. Perhaps a JSF / Primefaces expert could help me understand this?

              <h:form id="summaryForm">
              ...
              <p:tabView id="summaryTabView">
              ...
              <p:tab id="allTab" title="All">
              ...
              <script type="text/javascript">
                //<![CDATA[
                function updateAllRecordCount(){
                    var rowCount = PF('allTblWidget').paginator.cfg.rowCount;
                    //alert(rowCount);
                    var output = document.getElementById('summaryForm:summaryTabView:allTable:allCount');
                    if (output != null){
                        output.innerHTML = rowCount + " Records";
                    }
                }
                //]]>
              </script>
              <p:dataTable widgetVar="allTblWidget"
                             id="allTable" 
                             var="pb" 
                             value="#{statisticsBean.all}" 
                             emptyMessage="No data available!"
                             rowKey="#{pb.rowId}" 
                             scrollable="true" scrollHeight="440"
                             selection="#{statisticsBean.selectedBean}"
                             selectionMode="single"
                             editable="true"  
                             editMode="cell"
                             paginator="true"
                             rows="300"
                             paginatorAlwaysVisible="false">
                    <p:ajax event="filter"  oncomplete="updateAllRecordCount();"/>
                    <f:facet name="header">
                        <p:menubar styleClass="tableMenuClass">
                            ...
                            <f:facet name="options">
                                <h:outputText id="allCount" style="font-size:14px;" value="#{statisticsBean.all.size()} Records"/>
                            </f:facet>
                        </p:menubar>   
                    </f:facet>
                   ...
Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102
  • is it wrongly updated in the datatable itself or after your javascript updates the additional 'allCount' field? And please post version info and make it an [mcve] (e.g. are the tabs relevant?) – Kukeltje Mar 07 '17 at 15:42
  • The count is wrongly updated in the allCount field. Sometimes it is the previous count and sometimes it is correct and sometimes I have to hit the enter key twice for it to update correctly. The PF version is 5.1. – Carl Roberts Mar 07 '17 at 15:56
  • And tabs don't matter. – Carl Roberts Mar 07 '17 at 16:03

1 Answers1

0

The workaround listed below allows me to display the correct record count after filtering - I basically used the last 3 pagination attributes listed in the datatable element below to display the correct record count after filtering and took out the previous filter event, JavaScript function, and outputText field. This answer doesn't really answer the original question (I think there may be a bug in PF 5.1) but at least it provides a workaround for it.

<p:dataTable widgetVar="allTblWidget"
                         id="allTable" 
                         var="pb" 
                         value="#{statisticsBean.all}" 
                         emptyMessage="No data available!"
                         rowKey="#{pb.rowId}" 
                         scrollable="true" scrollHeight="440"
                         selection="#{statisticsBean.selectedBean}"
                         selectionMode="single"
                         editable="true"  
                         editMode="cell"
                         paginator="true"
                         rows="300"
                         paginatorAlwaysVisible="true"
                         paginatorTemplate="{CurrentPageReport}"
                         currentPageReportTemplate="{totalRecords} Records">
  • Then at least try to check if it works in a newer release. And if the PF rowcount IN the paginator shows the right amount, the problem is somewhere else – Kukeltje Mar 07 '17 at 18:51