Display summaryRow without using sortBy

UI Components for JSF
Post Reply
BeliSpricer
Posts: 4
Joined: 13 Aug 2019, 11:31

13 Aug 2019, 12:11

I'm using summaryRow to display data under some columns of a dataTable and it's not visible unless I specify the sortBy attribute in the dataTable or sort the table by clicking on a column header.
My problem is the fact that the column specified in sortBy has a highlighted header when the page loads, however I still want them to be highlighted when a user clicks on them for sorting.

So my question is: Is it possible to display a summayRow without sorting the dataTable.

Thank you for your time
PrimeFaces 8.0.7, Mojarra 2.2.7, GlassFish 4.1

kukeltje
Expert Member
Posts: 9605
Joined: 17 Jun 2010, 13:34
Location: Netherlands

15 Aug 2019, 15:33

I'd think it should just work, but without version info an a MCVE (use google) it is hard to tell. See also the 'please, please read me topic'

BeliSpricer
Posts: 4
Joined: 13 Aug 2019, 11:31

16 Aug 2019, 08:30

My versions are as follows: PrimeFaces 7.0, Mojarra 2.2.7, GlassFish 4.1.

This is the custom tag definition I use for displaying the PF dataTable, but simplified to make it easier to understand (Columns are normally inserted with JSF Facelets). Tell me if making a plainer example would be preferable for you.

Code: Select all

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:p="http://primefaces.org/ui"
                xmlns:f="http://xmlns.jcp.org/jsf/core"
                xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"
                xmlns:o="http://omnifaces.org/ui" 
                xmlns:h="http://xmlns.jcp.org/jsf/html">

    <c:set var="showEdit" value="#{showEdit ne null ? showEdit : false}"  />
    <c:set var="showDelete" value="#{showDelete ne null ? showDelete : false}" />
    <c:set var="showEditDelete" value="#{showEdit and showDelete}" />
    <c:set var="optionsColWidth" value="#{showEditDelete ? 50 : 24}" />

    <o:methodParam name="onEdit" value="#{onEdit}" />
    <o:methodParam name="onDelete" value="#{onDelete}" />

    <!-- #{rb.get('dataTable.emptyMessage')} -->

    <p:dataTable id="#{id}"
                 styleClass="table #{hideFilter ? 'datatable-search-hidden' : ''}"
                 tableStyleClass="datatable-fixed-height-#{rows}"
                 var="item" 
                 widgetVar="#{tableWidgetVar}"
                 value="#{blockView.dataModel}"
                 selection="#{blockView.rowSelected}"
                 emptyMessage=""
                 reflow="true"
                 editable="false"
                 selectionMode="single"
                 rows="#{rows}"
                 paginatorTemplate="#{paginatorTemplate}"
                 currentPageReportTemplate="#{currentPageReport}"
                 rowsPerPageTemplate="#{rowsPerPageTemplate}"
                 paginator="true"
                 paginatorPosition="bottom"
                 draggableColumns="true"
                 multiViewState="true"
                 lazy="true" 
                 scrollable="#{true}">

        <p:column filterValue="#{blockView.currentFilter.partner}"
                  sortable="true"
                  sortBy="#{item.partner}">
            <h:outputText id="COL-PARTNER"
                          value="#{item.partner}" />
        </p:column>
        <p:column filterValue="#{blockView.currentFilter.value}"
                  sortable="true"
                  sortBy="#{item.value}">
            <h:outputText id="COL-VAL"
                          value="#{item.value}" />
        </p:column>
        <p:column filterValue="#{blockView.currentFilter.esd}"
                  sortable="true"
                  sortBy="#{item.esd}">
            <h:outputText id="COL-EAD"
                          value="#{item.esd}" />
        </p:column>


        <p:summaryRow>
            <!-- this column is here so dataTable works correctly with draggableColumns -->
            <p:column style="visibility: hidden;"/>
            
            <p:column style="text-align: right">
                <h:outputText id="SUM-VAL"
                              value="#{blockView.summary['Sum']}" />
            </p:column>
            <p:column style="text-align: right">
                <h:outputText id="SUM-ESD"
                              value="#{blockView.summary['esdSum']}" />
            </p:column>

        </p:summaryRow>

    </p:dataTable>

</ui:composition>


Best regards.
PrimeFaces 8.0.7, Mojarra 2.2.7, GlassFish 4.1

kukeltje
Expert Member
Posts: 9605
Joined: 17 Jun 2010, 13:34
Location: Netherlands

16 Aug 2019, 10:09

start by not using a tag lib, no c:set, no omnifaces etc...

BeliSpricer
Posts: 4
Joined: 13 Aug 2019, 11:31

16 Aug 2019, 11:25

Tried using this, still no luck.

Code: Select all

<p:dataTable id="id"
                 var="item" 
                 value="#{blockView.dataModel}"
                 selection="#{blockView.rowSelected}"
                 emptyMessage=""
                 reflow="true"
                 editable="false"
                 selectionMode="single"
                 rows="10"
                 paginator="true"
                 paginatorPosition="bottom"
                 draggableColumns="true"
                 multiViewState="true"
                 lazy="true" 
                 scrollable="#{true}">

        <p:column sortable="true"
                  sortBy="#{item.partner}">
            <h:outputText id="COL-PARTNER"
                          value="#{item.partner}" />
        </p:column>
        <p:column sortable="true"
                  sortBy="#{item.val}">
            <h:outputText id="COL-VAL"
                          value="#{item.val}" />
        </p:column>
        <p:column sortable="true"
                  sortBy="#{item.esd}">
            <h:outputText id="COL-EAD"
                          value="#{item.esd}" />
        </p:column>

        <p:summaryRow>
            <!-- this column is here so dataTable works correctly with draggableColumns -->
            <p:column style="visibility: hidden;"/>

            <p:column style="text-align: right">
                <h:outputText id="SUM-VAL"
                              value="#{blockView.summary['valSum']}" />
            </p:column>
            <p:column style="text-align: right">
                <h:outputText id="SUM-ESD"
                              value="#{blockView.summary['esdSum']}" />
            </p:column>

        </p:summaryRow>

    </p:dataTable>
PrimeFaces 8.0.7, Mojarra 2.2.7, GlassFish 4.1

kukeltje
Expert Member
Posts: 9605
Joined: 17 Jun 2010, 13:34
Location: Netherlands

16 Aug 2019, 12:41

https://stackoverflow.com/help/minimal- ... le-example

So it works if you remove the 'draggableColums' ? Or other attributes?

BeliSpricer
Posts: 4
Joined: 13 Aug 2019, 11:31

19 Aug 2019, 07:41

Yes, it's the same with minimal attributes. And I've just realised i have misunderstood the way summaryRow works, as it groups rows based on the sorted column (I need a single row on the bottom of the table regardless of sorting). I guess I'll need to look into another solution.

Thank you for the help, much appreciated.
Best regards.
PrimeFaces 8.0.7, Mojarra 2.2.7, GlassFish 4.1

kukeltje
Expert Member
Posts: 9605
Joined: 17 Jun 2010, 13:34
Location: Netherlands

19 Aug 2019, 08:59

Ok, but please remember the steps to reducs as much of the code as possible while at the same time still be able to reproduce the problem... And only post those pieces of code

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 24 guests