primefaces Datatable footer total with filter – hack version

Posted: November 9, 2012 in web

xhtml: (be sure to use oncomplete not onsuccess)

....
                <f:facet name="footer">
                    <h:outputText value="#{bean.milesTotal}" id="milesTotal" />
                </f:facet>
....
<p:ajax  oncomplete="updateFooter()" event="filter" listener="#{bean.onFilter}"
				update="dummyPanel"  />
		</p:dataTable>

		<h:panelGroup id="dummyPanel">
            <h:outputText id="milesTotalHidden"
                value="#{reports.milesTotal} " />
		</h:panelGroup>

bean:

public void onFilter(FilterEvent e) {
        List<Car> filteredCars = (List<Car>) e.getData();
        if (filteredCars != null) {
            milesTotal = service.getMilesSum(filteredCars);
        }
        if (filteredCars == null && e.getFilters().size() == 0) {
            sumCars();
        }
    }

js:

function updateFooter(){
	$('#milesTotal').html($('#milesTotalHidden').html());
}
Advertisements
Comments
  1. Hi chawi3. This post is very good. But, if you don’t mind, I really appreciate some more details on that. Is it possible for you to send me all the source code related to this example? Or can you upgrade this post to a tutorial? It would be awesome! But if you can’t, please, can you help me to understand your code? I mean, I just need to check the right steps you took on building this so I can use in my work project. Thanks in advance.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s