First you need to get the proper column sorting event:
viewtopic.php?f=3&t=13365&p=61077#p61077
With this you will know which column is being sorted in the backing bean.
Second you need to created the summaryRow listener to handle each summary case:
In the XHTML (in dataTable):
Code: Select all
<p:summaryRow listener="#{backingBean.calculateTotal}">
<p:column colspan="3" style="text-align:right">
Total:
</p:column>
<p:column>
#{backingBean.total}
</p:column>
</p:summaryRow>
In the bean:
Code: Select all
public void calculateTotal(Object o) {
this.total = 0.0d;
String name = "";
if(o != null) {
if(o instanceof String) {
name = (String) o;
for(MyRowObject p : (List<MyRowObject>) dataTableModel.getWrappedData()) { // The loop should find the sortBy value rows in all dataTable data.
switch(sortColumnCase) { // sortColumnCase was set in the onSort event
case 0:
if(p.getcolumn0data().getName().equals(name)) {
this.total += p.getcolumn0data().getValue();
}
break;
case 1:
if(p.getcolumn1data().getName().equals(name)) {
this.total += p.getcolumn1data().getValue();
}
break;
}
}
}
}
}
Just keep in mind that this calculateTotal method is called at each summaryRow, and each time it scan all the table model data using string comparison. So use with care when you have several users at the same time.