ColumnToggle: hide some columns - primefaces

I'm working with primefaces 5.0 and i created one Primefaces:Datatable with Column:ColumnToggle but i need define initial columns to display.
How to hide some columns initially?
With property toggleable="false" i define that column not toggleable. Don't exist one property that defines initial columns?
<p:datatable ...>
<f:facet name="header">
<p:commandButton id="toggler" type="button" value="Data" icon="ui-icon-calculator" />
<p:columnToggler datasource="itemsDT" trigger="toggler" />
</f:facet>
...
</p:datatable>

How to hide some columns initially?
use visible="false".
Example
<p:column filterBy="#{vo.faxNo}" headerText="Fax No." sortBy="#{vo.faxNo}"
filterStyle="width: 90%" style="width: 130px;" visible="false" >
<h:outputText value="#{vo.faxNo}" />
</p:column>

Related

How to ignore group columns using Primefaces toggler

I have such toggler in dataTable with group columns:
<p:dataTable id="tbl">
<f:facet name="header">
<p:commandButton id="toggler_trigger" type="button"/>
<p:columnToggler id="column_toggler" datasource="tbl" trigger="toggler_trigger">
<p:ajax event="toggle" listener="#{viewModel.onToggle}" />
</p:columnToggler>
</f:facet>
<p:columnGroup type="header">
<p:row>
<p:column colspan="3" headerText="group of 3 columns" />
</p:row>
<p:row>
<p:column headerText="1 column" />
<p:column headerText="2 column" />
<p:column headerText="3 column" />
</p:row>
</p:columnGroup>
<p:column>
<h:outputText value="value 1" />
</p:column>
<p:column>
<h:outputText value="value 2" />
</p:column>
<p:column>
<h:outputText value="value 3" />
</p:column>
</p:dataTable>
How could I exclude group column with name "group of 3 columns" from toggler list? I want it consist only from three usual columns with colspan 1.
A p:column has a toggleable attribute which you can set to false to have a column not show up in the toggler. See page 112 of the 6.2 docs. It might very well also work for a p:columnGroup (although the documentation does not state this)

Primefaces Datatable Radiobutton submitting wrong values

I got a datatable with a custom layout selectoneradio. It doesnt submit correct values after the first row.
This is the datatable:
<h:form id="dataTableForm">
<br />
<p:dataTable id="absenceTable" var="absence" widgetVar="absenceTable"
value="#{adminController.absenceList}" rowIndexVar="rowIndex"
emptyMessage="Keine Absenzen mit ausstehender Genehmigung gefunden"
style="width:70%;margin-left:15%;margin-right:15%;margin-bottom:20px;margin-top:10px;"
rowKey="#{absence.id}" rows="30" paginator="true"
paginatorPosition="bottom" paginatorAlwaysVisible="false"
paginatorTemplate="{PageLinks}" sortBy="#{absence.startDate}"
sortOrder="descending"
filteredValue="#{adminController.filteredAbsences}">
<f:facet name="header">Mitarbeiterabsenzen mit ausstehender Genehmigung</f:facet>
<p:column>
<p:selectOneRadio id="action" value="#{absence.status}" required="false"
layout="custom" >
<f:selectItem itemValue="PENDING" noSelectionOption="true" />
<f:selectItem itemValue="APPROVED" />
<f:selectItem itemValue="REJECTED" />
<p:ajax event="valueChange" immediate="true" listener="#{adminController.checkBoxListener}" />
</p:selectOneRadio>
</p:column>
<p:column width="20">
<p:radioButton for="action" itemIndex="0" />
</p:column>
<p:column width="20">
<p:radioButton for="action" itemIndex="1" />
</p:column>
<p:column width="20">
<p:radioButton for="action" itemIndex="2" />
</p:column>
<f:facet name="footer">
<p:commandButton value="Speichern"
action="#{adminController.save()}" update="absenceTable" />
</f:facet>
</p:dataTable>
</h:form>
The row index and absence loop variable is defined on the datatable.
Its all in the same form.
The problem is, somehow, it only works for the first row. The other rows submit "on" instead of the value. I found in the generated html that they are not provided with value-tag like the radiobuttons in the first row are:
I guess its gonna be a stupid syntax issue or something... This is what i get debugging clicking on anything but the first row:
Im running on PF 5.2
This is a bug in PF5.2
The code runs smoothly on PF5.3

p:dataTable AutoComplete and ColumnToggler combination

When using autoComplete and columnToggler within a dataTable, I get a broken column-list in the column toggler.
That means, the column-list doesn't show the column-names but some javascript code instead (for each column).
Here is an example:
<p:commandButton id="showColsButton" type="button" value="Show Columns" />
<p:columnToggler datasource="myDataTable" trigger="showColsButton" />
<p:dataTable id="myDataTable" var="row" ...>
<p:column sortBy="#{row.myCol1}">
<f:facet name="header">
<div><h:outputText value="My Column 01" /></div>
<p:autoComplete ...>
<p:ajax event="itemSelect" update="myDataTable" />
</p:autoComplete>
</f:facet>
<h:outputText value="#{row.myCol1}" />
</p:column>
</p:dataTable>
Is this a bug or is there any solution for this specific problem?
Putting an input in the header facet is not valid. If you want to use it as a filter or something, put it in a f:facet name="filter".
<p:dataTable id="myDataTable" var="row" ...>
<p:column filterBy="#{row.myCol1}" sortBy="#{row.myCol1}">
<f:facet name="header">
<div><h:outputText value="My Column 01" /></div>
</f:facet>
<f:facet name="filter">
<p:autoComplete ...>
<p:ajax event="itemSelect" update="myDataTable" />
</p:autoComplete>
</f:facet>
<h:outputText value="#{row.myCol1}" />
</p:column>
But you might need to improve on the way the filter is used by not using the p:ajax but use an onchange=PF('dataTableWidget').filter(), adding a widgetVar attribute and adding filter attributes
See also
PrimeFaces showcase dataTable filter

In Primefaces, adding a row to a table with filtering

I'm using a datatable with filtering. This is the table declaration:
<p:dataTable id="#{tblId}" var="p" editable="true" editMode="cell"
resizableColumns="true" rowIndexVar="rowIndex" selectionMode="multiple"
rowKey="#{p.id}" selection="#{ppselection}"
emptyMessage="No Params in table" value="#{tblValue}" scrollable="true"
style="height:100%" sortMode="multiple" styleClass="#{styleClass}"
filteredValue="#{filteredParams}">
When adding a new row to the table, I want it to already be displayed according to the current filter. i.e. if the filter is "aa" and the row name is "aabbcc" then I want it displayed, but if the row name is "bbcc" then I don't want it displayed. Right now, all I came up with is decidng whether I want to manually add it to the filteredParams list or not.
This is an example of one of the columns in the table, although all the coulmns are filterable:
<p:column width="15%" id="ParameterColumn" headerText="Parameter" sortBy="#{p.name}"
filterBy="#{p.name}" filterMatchMode="contains">
<p:cellEditor id="Parameter">
<f:facet name="output">
<h:outputText id="param_name" value="#{p.name}" />
</f:facet>
<f:facet name="input">
<p:inputText id="nameInput" value="#{p.name}" style="width:99%"
validator="#{p.validateParamName}">
<p:ajax event="change"
update=":main_tabs:paramForm:ParamTbl, :main_tabs:paramForm:SplitedParamTbl" />
</p:inputText>
<p:messages for="nameInput" display="tooltip" />
</f:facet>
</p:cellEditor>
</p:column>
Thanks!!
You can trigger filtering in oncomplete method of ajax/button that adds new row:
oncomplete='tableWidgetVar.filter();'

Primefaces datatable column width does not work

i created a datatable which contains some test data. My problem is that some values are too large for one of my columns, that leads to a weird layout:
(after the order column two other columns should be displayed)
i already tried a few things out:
<p:column headerText="Orders" width="50"> no changes
<p:column headerText="Orders" style="max-width: 30px;"> makes the column smaler but the value is cut after 30px
adding after a few numbers a <br/> to force a breakline, but no changes
The order value is one big string. My goal is to change the orders column to a multiline column where the string value is splitted.
My datatable code:
<h:body>
<h:head>
</h:head>
<h:form id="form">
<p:dataTable id="customerTable" var="customer" value="#{customerDataTable.allCustomer}"
rows="25" paginator="true" emptyMessage="No customer found.">
<p:column headerText="Customer ID" style="text-align: center;">
<h:outputText value="#{customer.customerNumber}" />
</p:column>
<p:column headerText="Fist Name" style="text-align: center;">
<h:outputText value="#{customer.contactFirstName}" />
</p:column>
<p:column headerText="Last Name" style="text-align: center;">
<h:outputText value="#{customer.contactLastName}" />
</p:column>
<p:column headerText="Sales Employee Nr." style="text-align: center;">
<h:outputText value="#{customer.employee.employeeNumber}" />
</p:column>
<p:column headerText="Orders">
<h:outputText value="#{customer.allOrders}"/>
</p:column>
<p:column headerText="Payments" style="text-align: center;" >
<p:commandButton id="payment_btn" update=":form:p_display" oncomplete="paymentDialog.show()" icon="ui-icon-calculator">
<f:setPropertyActionListener target="#{customerDataTable.selectedCustomer}" value="#{customer}"/>
</p:commandButton>
<p:tooltip for="payment_btn" value="Click to see all payments" showEffect="fade" hideEffect="fade"></p:tooltip>
</p:column>
<p:column headerText="Contact Data" style="text-align: center;" >
<p:commandButton id="contact_btn" update=":form:c_display" oncomplete="contactDialog.show()" icon="ui-icon-home">
<f:setPropertyActionListener target="#{customerDataTable.selectedCustomer}" value="#{customer}"/>
</p:commandButton>
<p:tooltip for="contact_btn" value="Click to see the detailed contact data" showEffect="fade" hideEffect="fade"></p:tooltip>
</p:column>
</p:dataTable>
</h:form>
</h:body>
In other threads i found solutions using css but that didn't work either (the reason could be that i dont now how and where the css file and methods should be created).
If you want rows to break you can use CSS. Try adding this to your style
.ui-datatable td,.ui-datatable th {
white-space: normal;
}
This won't work if there are no blank spaces in your text, because the browser won't know where to break the line, in that case you could make use of the wbr tag, but it's important to say it's not supported by IE
See also:
http://www.w3schools.com/tags/tag_wbr.asp
try adding this to datatable scrollable="true" it worked.