2013-08-02 36 views
0

我有困難排序動態的dataTablePrimefaces 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> 

我使用的是@SessionScoped豆其中databaseSearch.customerList將查詢數據庫並填充數據表。當我點擊列名進行排序時,排序箭頭標記會更改,但表內容不會排序。

我使用PF 3.4.2

+0

這看起來像http://stackoverflow.com/questions/5020725/sorting-is-not-working-in-datatable-in-primefaces的重複嘗試 – RJA

回答

1

如果您在每次請求這是不行的查詢數據庫中的getCustomerList方法。你可以用一個局部變量

public class DatabaseSearch{ 

    private List<C> customerList; 

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