Primefaces dynamic columns p:columns sort specific columns

时间:2016-07-11 21:09:27

标签: jsf primefaces datatable dynamic-columns

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 个答案:

答案 0 :(得分:3)

Primefaces在版本5.1.3和5.2.0中为p:column(s)添加了新属性:

  • 排序
  • 过滤

以下是已解决问题的链接:

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

示例取决于我上面的代码:

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

    //GETTER
    ...
}

bean中有一个给定的List<ColumnModel> columnModel

<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>