0
votes

After filtering of primefaces 'tasksDataTable', the 'number of records' does not update. For example before filtering number of records is 45, and by filtering table i get 3 records as result. But 'number of records' is already 45 (i expect to show 3 for 'number of records' after filtering). How can i handle it?

<p:dataTable var="recordEntity"
             id="rulesDataTable"
             widgetVar="rulesDataTable"
             value="#{bossCartable.tasksDataTable}"
             paginator="true"
             paginatorAlwaysVisible="false"
             rows="#{paginationModel.rows}"
             paginatorTemplate="#{paginationModel.paginationTemplate}"
             rowsPerPageTemplate="#{paginationModel.rowsPerPageTemplate}"
             currentPageReportTemplate="#{paginationModel.currentPageReportTemplate}"
             selectionMode="single"
             selection="#{bossCartable.selectedRuleRow}"
             rowIndexVar="rowIndex"
             sortBy="#{recordEntity.id}"
             emptyMessage="No record found!"
             rowKey="#{recordEntity.id}"
             resizableColumns="true"
>

    <f:facet name="header">
        <div class="row align-content-center">
            Tasks
            <h:outputLabel value="number of records: #{bossCartable.tasksDataTable.size()}"/>
        </div>
    </f:facet>

    <p:column headerText="id" width="5%" filterMatchMode="contains"
              filterBy="#{recordEntity.id}" sortBy="#{recordEntity.id}" sortable="true">
        <h:outputText value="#{recordEntity.id}"/>
    </p:column>


    <p:column headerText="description" filterMatchMode="contains"
              filterBy="#{recordEntity.description}">
        <h:outputText value="#{recordEntity.description}"/>
    </p:column>

    <p:column headerText="startDate" width="8%" filterMatchMode="contains"
              filterBy="#{recordEntity.startDate}">
        <h:outputText value="#{recordEntity.startDate}"/>
    </p:column>

    <p:column headerText="endDate" width="8%" filterMatchMode="contains"
              filterBy="#{recordEntity.endDate}">
        <h:outputText value="#{recordEntity.endDate}"/>
    </p:column>


</p:dataTable>
1

1 Answers

3
votes

With non lazy loading the filtered value can be stored using the filteredValue attribute. See: https://primefaces.github.io/primefaces/8_0/#/components/datatable

This will allow you to use:

<p:dataTable value="#{bossCartable.tasksDataTable}"
             filteredValue="#{bossCartable.tasksFiltered}"
             ...>
</p:dataTable>

and

#{bossCartable.tasksFiltered.size()}

where tasksFiltered should point to a writable List.

Also, your header facet will not be updated by magic, you should put you text in a component and update that component on the filter event of the data table.

See also: