0
votes

i have a datatable with dynamic columns, defined by a columnModel. The String property links to the correct field (used for value output). The sort String equals the property, but some columns should not be sortable, sort is null or emtpy (tried both) there:

public class ColumnModel {
    private String property;
    private String sort;
    private int width;

    //GETTER
    ...
}

I use a List of that models to create my dynamic columns. The use of the width is working well:

<p:dataTable value="#{bean.items}" var="item" ... >

    <p:columns value="#{bean.columnModel}" var="column" sortBy="#{column.sort}" width="#{column.width}">
        ...
    </p:columns>
</p:dataTable>

My Question: sortBy does not allow a null or an emtpy value. Otherwise i get a parse exception where it says, it cannot parse #{item.}. primefaces seems to add 'item' (my var of the datatable) automatically before the given sortfield.

How can some columns be ignored?

Thanks for your answeres!

Using primefaces 5.0.9 with Wildfly 9.0.2

1
Tried a newer PF version? And "I can't use a newer version" is not a correct response ;-). Trying to see if it is solved in a newer version is always possible in a simple test project (minimal reproducible example).Kukeltje
thx for your answer, in primefaces 5.2 there is a new attribute for exactly that problem.kaiser
You are welcome. You can create an answer yourself. Please do as it might be helpful for othersKukeltje

1 Answers

3
votes

Primefaces added new attributes for p:column(s) in version 5.1.3 and 5.2.0:

  • sortable
  • filterable

Here is the link to the solved Issue:

https://code.google.com/archive/p/primefaces/issues/5021

Example depending on my code above:

public class ColumnModel {
    private String property;
    private boolean sortable;
    private int width;

    //GETTER
    ...
}

With a given List<ColumnModel> columnModel in bean:

<p:dataTable value="#{bean.items}" var="item" ... >

    <p:columns value="#{bean.columnModel}" var="column" sortBy="#{item[column.property]}" field="#{column.property}" sortable="#{column.sortable}" width="#{column.width}">
        ...
    </p:columns>
</p:dataTable>