Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>EDIT:</strong> </p> <p>Solution posted below (LazyTable) works for the p:dataTable backed with LazyDataModel. Overriden <strong>load</strong> method is called after every update/refresh on the desired table and it handles sort properly. The problem with simple p:dataTable is that it performs predefined sort only on the first load, or after the click on sort column. This is a normal behaviour of a simple table. </p> <p>So what are your possibilities for simple table :</p> <ul> <li><p>Don't sort the table after update, but remove the sort column so end user is not missinformed. Add this to your action listener or action method for your update button :</p> <pre><code>UIComponent table = FacesContext.getCurrentInstance().getViewRoot().findComponent(":dataTablesForm:dataTableId"); table.setValueExpression("sortBy", null); </code></pre></li> <li><p>Update the sort of the table manually by script. This is not the best solution, but primefaces doesn't provide any client side function for "resorting" the table. Basically you know that only one column at a time can be sorted and this column has a .ui-state-active. You can use it in a script and trigger 2 clicks on that column (1. click - other sort order, 2. click - back to current sort order).</p> <pre><code> &lt;h:form id="mainForm"&gt; &lt;div id="tableDiv"&gt; &lt;p:dataTable id="dataTable" var="item" value="#{testBean.dummyItems}"&gt; . . . &lt;/p:dataTable&gt; &lt;p:commandButton value="Refresh" oncomplete="refreshSort();" update=":mainForm:dataTable"/&gt; &lt;/div&gt; </code></pre> <p> And script function :</p> <pre><code>function refreshSort(){ jQuery('#tableDiv').find('.ui-state-active').trigger('click'); jQuery('#tableDiv').find('.ui-state-active').trigger('click'); } </code></pre></li> </ul> <p>I know this is not the best workaround, but it works. You can use it as an inspiration to make something better.</p> <h3>LazyTable</h3> <p>IMHO the most proper way is to update directly the component you want. So for example : </p> <pre><code>&lt;h:form id="dataTableForm"&gt; &lt;p:dataTable id="dataTableToUpdate"&gt; . . . &lt;/p:dataTable&gt; &lt;p:commandButton value="Refresh" update=":dataTableForm:dataTableToUpdate" /&gt; &lt;/h:form&gt; </code></pre> <p>It should work fine in this scenario (I suppose it is your purpose) : Open the .xhtml with your p:dataTable, sort some column (keep the facelet opened), update dataTables data from another .xhtml for example, click on refresh button. The dataTable should show your added value in correct (previously chosen) sort order - sorting was performed after update.</p> <p>Hope it helped !</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload