2
votes

So lets say I have the following table:

        <p:dataTable id="genaricTable" var="item" value="#{genaricBean.currentValue}" >
            <p:columnGroup type="header"> 
                <p:row>
                    <p:column rowspan="" headerText="value1"/>
                    <p:column rowspan="" headerText="value2"/>
                    <p:column rowspan="" headerText="value3"/>
                </p:row> 
            </p:columnGroup>  
            <p:subTable var="subItem" value="#{item.subItemList}" >
                <f:facet name="header">  
                  #{item.header}
                </f:facet> 
                <p:column>
                    <h:outputText value="#{subItem.value1}"/>
                </p:column>
                <p:column>
                    <h:outputText value="#{subItem.value1}"/>
                </p:column>
                <p:column>
                    <h:outputText value="#{subItem.value1}"/>
                </p:column>
            </p:subTable>
        </p:dataTable>

Is there a way I can filter/sort by the subcolumn tables with the built in primefaces components? The only thing I can think of is putting in a custom command link to do it.

2
As Feva pointed, the hierarquical data structure and particularities of the subtable does not work well. As a work-around, how about faking sub-tables with several tables and using CSS to give them the feel of one big table?Mindwin

2 Answers

1
votes

You're right. It doesn't work when you add the sortBy attribute to the column definition inside of the subTable.

There is however a very easy solution. Add it to the column definition inside of your header columnGroup. PrimeFaces DO process this attribute if defined there.

I suppose this approach could maybe work for the filterBy as well, I didn't try it out though.

<p:columnGroup type="header"> 
    <p:row>
        <p:column rowspan="" headerText="value1" sortBy="#{subItem.value1}"/>
        <p:column rowspan="" headerText="value2"/>
        <p:column rowspan="" headerText="value3"/>
    </p:row> 
</p:columnGroup>

EDIT : You do of course need to take your underlying dataset into consideration and maybe use something different as sort Expression or maybe also write a little workaround in your Managed Bean, because it's never that simple with hierarchical data. I used that Expression simply to illustrate the solution.

-1
votes

for sorting the subcolumn table, you can add in sortBy in the subcolumn..something similar like this..

            <p:column sortBy="#{subItem.value1}">
                <h:outputText value="#{subItem.value1}"/>
            </p:column>

have a try..