简体   繁体   English

Primefaces dataTable排序似乎不起作用

[英]Primefaces dataTable Sorting does not seem to work

I am having difficulties sorting a dynamic dataTable 我在排序动态数据表时遇到困难

dataTable 数据表

<h:form prependId="false" id="Main_Form">
    <p:dataTable id="dataTable" var="c" value="#{databaseSearch.customerList}"  
        paginator="true" rows="10" paginatorAlwaysVisible="false"
        paginatorTemplate="Page {CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}  Rows per page {RowsPerPageDropdown}"  
        rowsPerPageTemplate="5,10,15,30" draggableColumns="True">  
        <p:column sortBy="#{c.machine}" headerText="Machine">  
            <h:outputText value="#{c.machine}" />   
        </p:column>  
        <p:column sortBy="#{c.company}" headerText="Company">  
            <h:outputText value="#{c.company}" />
        </p:column>  
        <p:column sortBy="#{c.contact}" headerText="Contact">  
            <h:outputText value="#{c.contact}" />  
        </p:column>  
        <p:column sortBy="#{c.phone}" headerText="Phone">  
            <h:outputText value="#{c.phone}" />  
        </p:column>  
        <p:column sortBy="#{c.email}" headerText="Email"> 
            <h:outputText value="#{c.email}" />
        </p:column>  
        <p:column exportable="false" headerText="Modify">   
            <center>
                <p:commandButton id="basic" value="Update"
                    action="#{updateEntry.setMachine(c.machine)}"
                    oncomplete="dlg1.show();"
                    styleClass="ui-Machinebutton" update=":Update_Entry"/>
                <p:tooltip for="basic" value="Update/Delete Database Entry"
                    showEffect="fade" hideEffect="fade" />
            </center>
        </p:column> 
    </p:dataTable>
</h:form>

I am using a @SessionScoped bean where databaseSearch.customerList would query the database and populate the dataTable. 我正在使用@SessionScoped bean,其中databaseSearch.customerList将查询数据库并填充dataTable。 When I click on the column name to sort, the sort arrow mark changes but the table contents do not sort. 当我单击列名称进行排序时,排序箭头标记会更改,但表内容不会排序。

I am using PF 3.4.2 我正在使用PF 3.4.2

If you are querying your database in your getCustomerList method in every request this will not work. 如果要在每个请求的getCustomerList方法中查询数据库,则此方法将无效。 You may try with a local variable 您可以尝试使用局部变量

public class DatabaseSearch{

    private List<C> customerList;

    public List<C> getCustomerList () {
        if (customerList == null)
            customerList = dao.getcustomerList();
        return customerList ;
    }
}

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

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