Tengo una DataTable (Primefaces) y no me funciona la opción de ordenar.
Una de las columnas tiene un filtro, y si escribo algo en el filtro y luego doy a la flecha de ordenar la columna, funciona, pero no ordena si no se utiliza el filtro.
He visto por internet que este problema es muy común pero ninguna de las soluciones que he leído me ha dado resultado.
OverView.xhtml
Código:
<p:dataTable var="row" value="#{overviewTableBean.overviewTableDataModel}" id="overviewTable" paginator="true" paginatorPosition="bottom" rows="10" paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}" rowsPerPageTemplate="5,10,15" selection="#{overviewTableBean.selectedRows}" emptyMessage="#{messages['view.campaign.overview.table.empty.rows']}"> <p:column id="columnNameCampaign" sortBy="#{row.campaignName}" filterBy="#{row.campaignName}" headerText="#{messages['view.campaign.overview.table.column.nameCampaign']}" filterMatchMode="contains"> <p:commandLink action="#{processCampaignBean.editCampaign(row.campaignId)}" ajax="false"> <h:outputText value="#{row.campaignName}"/> </p:commandLink> </p:column> <p:column id="columnStatus" sortBy="#{row.campaignState}" headerText="#{messages['view.campaign.overview.table.column.stateCampaign']}"> <dms:outputText key="#{ligatusUtilities.getEnumDisplayString(row.campaignState)}"/> </p:column> <p:column id="columnAis" sortBy="#{row.totalAis}" headerText="#{messages['view.reporting.ais']}"> <dms:formatNumber value="#{row.totalAis}" pattern="#{messages['i18n.format.units.pattern']}" emptyText="-"/> </p:column> </p:dataTable>
OverviewTableBean.java
Código:
@Named @SessionScoped public class OverviewTableBean extends BaseBean implements Serializable { private static final long serialVersionUID = -930803734182351917L; @Inject private CampaignOverviewTableDao campaignOverviewTableDao; @Inject private ChartBean chartBean; private OverviewTableDataModel overviewTableDataModel = null; private CampaignOverviewTableLine[] selectedRows = null; private SelectItem[] campaignStateList = new SelectItem[5]; public OverviewTableBean() { campaignStateList[0] = new SelectItem("", "All"); campaignStateList[1] = new SelectItem(CampaignState.SETUP); campaignStateList[2] = new SelectItem(CampaignState.CLEARED); campaignStateList[3] = new SelectItem(CampaignState.ONLINE); campaignStateList[4] = new SelectItem(CampaignState.OFFLINE); } public OverviewTableDataModel getOverviewTableDataModel() { overviewTableDataModel = new OverviewTableDataModel(getRows()); return overviewTableDataModel; } public void setOverviewTableDataModel(final OverviewTableDataModel aOverviewTableDataModel) { overviewTableDataModel = aOverviewTableDataModel; } public SelectItem[] getCampaignStateList() { return campaignStateList; } public void setCampaignStateList(final SelectItem[] aCampaignStateList) { campaignStateList = aCampaignStateList; } public CampaignOverviewTableLine[] getSelectedRows() { return selectedRows; } public void setSelectedRows(final CampaignOverviewTableLine[] aSelectedRows) { selectedRows = aSelectedRows; } /** * Returns the table rows. * * @return the table rows. */ public List<CampaignOverviewDataLine> getRows() { return campaignOverviewTableDao.getCampaignOverviewDataByFilter(chartBean.getFilterCriteria()); } /** * Sets the campaign filter */ protected void setCampaignsFilter() { if(selectedRows == null) { return; } final HashSet<Long> selectedCampaignIds = new HashSet<Long>(3); for(final CampaignOverviewDataLine row : selectedRows) { selectedCampaignIds.add(((CampaignOverviewTableLine)row).getCampaignId()); } chartBean.getFilterCriteria().setCampaignIdList(selectedCampaignIds); } }