primefaces Datatable update footer totals with filter – RequestContext Callback version

Posted: November 13, 2012 in web

xhtml: (be sure to use oncomplete not onsuccess)

<p:dataTable...>
....
                <f:facet name="footer">
                    <h:outputText value="#{bean.milesTotal}" id="milesTotal" />
                </f:facet>
....
</p:dataTable...>

<p:ajax  oncomplete="handleComplete(xhr, status, args)" event="filter" listener="#{bean.onFilter}"  />
		</p:dataTable>	

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();
        }
	RequestContext rc = RequestContext.getCurrentInstance();
        rc.addCallbackParam("milesTotal", milesTotal);
    }

js:

function handleComplete(xhr, status, args){
	$('#milesTotal').html(args.milesTotal);
}
Advertisements
Comments
  1. csaez says:

    i need the same but an disabled atributte for comandbutton

  2. Omar says:

    Good work man 🙂

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