0

I try to change Primefaces dataTable columns sequence using displayPriority parameter. But it does not work.If I try to change isVisible parameter or Width parameter of column everything works fine, but displayPriority does not work, why?

My xhtml:

<p:dataTable id="dataTableIncomingDoc"
             var="item"
             scrollable="true"
             scrollHeight="100%"
             scrollWidth="100%"
             showGridlines="true"
             selectionMode="single"
             draggableColumns="true"
             resizableColumns="true"
             size="small"
             styleClass="fixed-size"
             selection="#{docsBean.docEntitySelected}"
             rowKey="#{item.id}"
             value="#{docsBean.loadDocsList()}">

 
    <p:column id="registrationDate"
              headerText="Reg. date"
              width="100"
              filterBy="#{item.registrationDate}"
              sortBy="#{item.registrationDate}"
              filterMatchMode="contains">
        <h:outputText value="#{item.registrationDate}"/>
    </p:column>
 
    <p:column id="regNr"
              headerText="Reg. Nr."
              width="100"
              filterMatchMode="contains"
              sortBy="#{item.regNr}"
              filterBy="#{item.regNr}">
        <h:outputText value="#{item.regNr}"/>
    </p:column>
 
 
    <p:column id="documentNr"
              headerText="Doc. Nr."
              width="100"
              filterMatchMode="contains"
              sortBy="#{item.docNr}"
              filterBy="#{item.docNr}">
        <h:outputText value="#{item.docNr}"/>
    </p:column>
</p:dataTable>

My bean:

public List<DocEntity> loadDocsList() {
 
    var dataTable = (DataTable) FacesContext.getCurrentInstance().getViewRoot().findComponent("mainForm:dataTableIncomingDoc");
 

    var a = dataTable.getColumns().get(1);
    var b = dataTable.getColumns().get(2);
 
    ((Column) a).setDisplayPriority(2);
    ((Column) b).setDisplayPriority(1);
 
    PrimeFaces.current().ajax().update(dataTable);
 
    return docsList;
}
Pegus
  • 31
  • 2
  • Does `displayPriority` work if you just put it on each column in the XHTML? It just doesn't work if you try and use it server side? – Melloware Jan 30 '23 at 13:06
  • Yes, it work if I put in each column in the XHTML displayPriority parameter. But I want to do it from server side, from Bean dynamically, because position of each columns depends on User settings and each column position is located in Database. – Pegus Jan 30 '23 at 13:13
  • I have a feeling clearly that your settings are being wiped away by the `PrimeFaces.current().ajax().update(dataTable);` i think you might have to do it a different way to set those values server side? – Melloware Jan 31 '23 at 12:25

0 Answers0