Archive | primefaces RSS for this section

why primefaces’ datatable column not sortable?

Just found column in primefaces datatable not sortable:

<p:dataTable id=”table_template” var=”templateVar” value=”#{manageTemplateCtl.templateList}”
rowKey=”#{templateVar.id}” rows=”20″
paginator=”true”
paginatorTemplate=”{CurrentPageReport} {FirstPageLink}
{PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}”>

<p:column sortBy=”#{templateVar.name}” style=”width:300px”>
<f:facet name=”header”>
<h:outputText value=”#{messages.label_name}”/>
</f:facet>
<h:outputText value=”#{templateVar.name}”/>
</p:column>

<p:column headerText=”#{messages.label_description}” style=”width:350px”>
<h:outputText value=”#{templateVar.description}”/>
</p:column>
<p:column headerText=”#{messages.label_templateMode}” sortBy=”#{templateVar.mode}”
style=”width:120px”>
<h:outputText value=”#{templateVar.mode}”/>
</p:column>

</p:dataTable>

Cause:

Primefaces’ datatable sorting not work, if value was populated in get value method eg.manageTemplateCtl.templateList

Solution:

Avoid populate list value in get method, but Initiate the templateList in controller, and return the templateList initiated in getTemplateList()