1

I have a table which I want to hide particular column as below.

For example, I want to hide 3 last columns under the tag <p:columns> </p:columns>

<p:dataTable id="dynaDataTable" var="row" value="#{onListBean.rowList}" style="font-size:12px;"
        selectionMode="single" selection="#{onListBean.selectedRow}" rowKey="#{row.s_nr}"
        widgetVar="dynaTable" emptyMessage="Empty!" rowIndexVar="rowIndex"
        scrollable="true" scrollHeight="100%">

        <p:column id="rowNumber" exportable="false" headerText="#" style="max-width:50px; width:20px" >
            <h:outputText value="#{rowIndex+1}" />
        </p:column>
        <p:columns headerText="#{column.header}" value="#{onListBean.columns}" var="column" >
            <div style="text-align: center;">
                <h:outputText value="#{row[column.property]}"/>
            </div>
        </p:columns> </p:dataTable>

Any Idea?

Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102
itro
  • 7,006
  • 27
  • 78
  • 121

2 Answers2

2

Just create a method in your bean which will return the columns you want to display, and use that with <p:columns value="...". If that is somehow not possible, you can also use the visible attribute, for example visible="#{column.header ne 'excludeMe'}".

If you are looking to display columns based on the available screen width, you should have a look at either the responsivePriority property, or <p:dataTable reflow="true".

See also:

Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102
1

I couldn't understand from your question if you need it done using a UI component or not. If yes, Primefaces has a pretty nice component <p:columnToggler /> which lets you hide and show the table columns whenever you want. If you were talking about the other scenario, I still think you could do some trick with columntoggler while not displaying it in the UI.

wolfhunter
  • 33
  • 7