首页 > 解决方案 > p:datatable 组件不排序,只有当我过滤它之前

问题描述

我试图在 Datatable 中显示我的 mysql 数据库中的数据,并且一切正常,现在我试图包含一个过滤器和排序功能,但是当我测试它并按下排序箭头时,没有任何反应,只有当我过滤首先是数据表,然后一切正常。

我尝试使用 primeface Attributes filterBy 和 sortBy,并且由于现有功能,我认为它与更新问题有关

<p:dataTable id="test3" scrollable="true" scrollHeight="150"  var="Foo" value="#{Foo.bar}">
    
       <p:column headerText="#{msg['default-description-key']}" 
       sortBy="#{Foo.keyString}" 
       filterBy="#{Foo.keyString}">
                                            
           <p:outputLabel  value="#{Foo.keyString}" 
           style="float:center"/>     
                          
       </p:column>                                       
       <p:column headerText="#{msg['default-description-count']}" 
       sortBy="#{Foo.count}" filterBy="#{Foo.count}">
                                            
           <p:outputLabel value="#{Foo.count}" 
           style="float:center"/>
                                        
       </p:column>                                        
       <p:column headerText="#{msg['default-description-register.key']}">
                                            
           <p:commandLink value="#{msg['default-description- 
           register.key.link']}" action="#{Foo.bar(Foo.keyString)}"/>
                                        
       </p:column>
                                   
</p:dataTable>

我希望能够对数据表进行排序而无需之前对其进行过滤

标签: jsfprimefaces

解决方案


  • 在您的 bean 中创建一个单独的列表(不要忘记 getter 和 setter)并将其链接到 p:dataTable 组件中的属性 filteredValue
  • 将表格放在 h:form 中
  • 使用 h:outputText 而不是 p:outputLabel

推荐阅读