简体   繁体   English

带有子表的数据表上的Primefaces Filterby / Sort

[英]Primefaces Filterby/Sort on a datatable with a subtable

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? 有没有一种方法可以使用内置的primefaces组件按子列表进行过滤/排序? The only thing I can think of is putting in a custom command link to do it. 我唯一能想到的就是放入自定义命令链接来执行此操作。

You're right. 你是对的。 It doesn't work when you add the sortBy attribute to the column definition inside of the subTable. 当您将sortBy属性添加到subTable内的列定义时,它不起作用。

There is however a very easy solution. 但是,有一个非常简单的解决方案。 Add it to the column definition inside of your header columnGroup . 将其添加到标题columnGroup内的列定义中。 PrimeFaces DO process this attribute if defined there. PrimeFaces DO会在该属性定义的情况下处理该属性。

I suppose this approach could maybe work for the filterBy as well, I didn't try it out though. 我想这种方法可能也适用于filterBy ,但是我没有尝试过。

<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. 编辑:当然,您确实需要考虑基础数据集,并可能使用其他不同的排序表达式,或者在Managed Bean中编写一些变通办法,因为使用分层数据从未如此简单。 I used that Expression simply to illustrate the solution. 我只是用表达式来说明解决方案。

for sorting the subcolumn table, you can add in sortBy in the subcolumn..something similar like this.. 为了对子列表进行排序,可以在子列中添加sortBy ..类似的东西。

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

have a try.. 试试..

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM