p:datatable摘要行计算 [英] p:datatable summary row calculation

查看:178
本文介绍了p:datatable摘要行计算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 p:dataTable 非常类似于 showcase
不幸的是,展示使用随机生成的值为 p:summaryRow

I have a p:dataTable pretty similar to the showcase. Unfortunatly, the showcase uses randomly generated values for the p:summaryRow.

参考展示,想像这辆汽车有一个价格属性。

Refering to the showcase, imagine the car had a price attribute.

我如何总结按照指定列分组的汽车的价格,以便在总结行中显示?

推荐答案

我有与您相同的问题,并从原点找到正确的用法blog
从原点论坛的SummaryRow

I have same problem with you and found correct usage from primefaces blog SummaryRow from primefaces forum

这是一些示例,显示总和价格的正确计算,计数...

this is some example show correct calculation for sum price, count...

监听器获取组属性,它是可用于计算总计的sortBy值,任何其他操作。

Listener gets the group property which is the sortBy value which you can use to calculate totals or any other operation.

<p:summaryRow listener="#{backingBean.calculateTotal}"> 
                        <p:column colspan="3" style="text-align:right"> 
                            Total: 
                        </p:column> 

                        <p:column> 
                            #{backingBean.total}
                        </p:column> 
                    </p:summaryRow>

/* listener method in your bean */
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;
                }
            }
        }
    }
}

这篇关于p:datatable摘要行计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆