Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SummaryRow in p:dataTable not working

I am trying to show a total value on my dataTable, my code is similar to the primefaces showcase DataTable - SummaryRow and still not working.

<p:dataTable id="dtCaixa" var="list" value="#{caixaMB.list}" paginator="true" rows="7" 
                                 paginatorPosition="bottom" rowsPerPageTemplate="10,15,20" liveScroll="true"
                                 paginatorAlwaysVisible="false"  emptyMessage="Nenhuma entrada!" liveResize="true">                                                        


                        <p:column headerText="Nome" sortBy="#{list.produtoFK.nome}" style="width:15%;">
                            <h:outputText value="#{list.produtoFK.nome}" />
                        </p:column>

                        <p:column headerText="Funcionário" sortBy="#{list.funcionarioFK.nome}">
                            <h:outputText value="#{list.funcionarioFK.nome}" />
                        </p:column> 

                        <p:column headerText="Quantidade" sortBy="#{list.quantidade}">
                            <h:outputText value="#{list.quantidade}" />
                        </p:column>

                        <p:column headerText="Preço" >                                
                            <h:outputText value="#{list.produtoFK.preco}" rendered="#{not empty list.produtoFK}">
                                <f:convertNumber pattern="R$ #0.00" locale="pt_BR"/>
                            </h:outputText>
                        </p:column>

                        <p:column headerText="Total" sortBy="#{list.total}" >
                            <h:outputText value="#{list.total}" >
                                <f:convertNumber pattern="R$ #0.00" locale="pt_BR"/>
                            </h:outputText>
                        </p:column>

                        <p:column headerText="Remover" class="centered">
                            <p:commandButton icon="ui-icon-trash" title="excluir"  onclick="PF('confirmaExclusao').show();">
                                <f:setPropertyActionListener target="#{caixaMB.itemSelecionado}" value="#{list}" />
                            </p:commandButton>                                    
                        </p:column>

                        <p:summaryRow>
                            <p:column colspan="3" style="text-align:right">
                                <h:outputText value="Total:" />
                            </p:column>
                            <p:column>
                                <h:outputText value="#{caixaMB.total}">                                        
                                </h:outputText>
                            </p:column>
                        </p:summaryRow>

                    </p:dataTable>

Does anybody have any idea why is this happening?

like image 785
Thales Avatar asked Jun 06 '16 18:06

Thales


2 Answers

You need to sort the dataTable using at least one column if you want to use summaryRow. Check the Primefaces documentation.

E.g. put the attribute sortBy="#{myList.myOrderValue}" on the <p:datatable> tag.

like image 131
mcastilloy2k Avatar answered Oct 18 '22 23:10

mcastilloy2k


I think what you're trying to achieve is the overall total of the column showing up at the bottom. I was caught out by the summaryRow function too, until I realised it was a grouping function and not a totalling summary. What I did you get around this was for the last column I added some footerText. You will have to calculate your totals manually (iterate over your dataset etc), then you can use something like:

<p:column style="text-align: right" footerText="$ #{invoicesbean.total}">
    <f:facet name="header">
        <h:outputText value="Amount" />
    </f:facet>
........ etc

This worked well for me but YMMV!

like image 1
Darren Smith Avatar answered Oct 19 '22 00:10

Darren Smith