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.
Related
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
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
I am using PF 5.3, on (weblogic 11g/jsf2.0/java 1.6).
I thought the issue of not shown emptyMessage in Datatable is fixed in 5.3, but inspite of using the latest version, i still dont see the message. Below is my sample code.
<p:dataTable id="attaDt" var="fileRow" value="#{pendpaybean.selectedPayDetailsFiles}"
rowIndexVar="rowIndex"
emptyMessage="No Files Uploaded"
>
<p:column headerText="Uploaded Date"
width="15px;" style="text-align:center"
>
<h:outputText value="#{fileRow.columns[0]}" />
</p:column>
<p:column headerText="Uploaded By"
width="30px;" style="text-align:center"
>
<h:outputText value="#{fileRow.columns[3]}" />
</p:column>
</p:datatable>
Any help ?
Your code works well. NOTE I put attribute value to null for showing emptyMessage.
Your adapted code:
<h:body>
<h:form>
<p:dataTable id="attaDt" value="#{null}" var="fileRow" rowIndexVar="rowIndex" emptyMessage="No Files Uploaded">
<p:column headerText="Uploaded Date" width="15px;" style="text-align:center">
<h:outputText value="#{fileRow.columns[0]}" />
</p:column>
<p:column headerText="Uploaded By" width="30px;" style="text-align:center">
<h:outputText value="#{fileRow.columns[3]}" />
</p:column>
</p:dataTable>
</h:form>
</h:body>
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>
I'm trying to put a scrollable datatable inside of a rowExpansion tag, but the resulting datatable comes out all weird, like this:
Code:
<p:rowExpansion>
<h:panelGrid id="display" columns="2" cellpadding="4"
styleClass="ui-widget-content"
columnClasses="label, value">
<h:outputText value="Registrerad:"/>
<h:outputText id="registered" value="#{campaignOfferGroupView.formatDate(offerGroup.registerDate)}"/>
<h:outputText value="Senast ändrad:"/>
<h:outputText id="changeDate" value="#{campaignOfferGroupView.formatDate(offerGroup.changeDate)}"/>
<h:outputText value="Ändrad av:"/>
<h:outputText id="changedBy" value="#{offerGroup.changedBy}"/>
</h:panelGrid>
<p:dataTable var="campaignCode" value="#{campaignOfferGroupView.getCampaignCodesForGroup(offerGroup.id)}"
scrollable="true" scrollHeight="120">
<f:facet name="header">
Kampanjkoder tillhörande kampanjerbjudandegruppen
</f:facet>
<p:column headerText="ID">
#{campaignCode.id}
</p:column>
<p:column headerText="Namn">
#{campaignCode.description}
</p:column>
<p:column headerText="Start">
#{campaignCode.startDate}
</p:column>
<p:column headerText="Stop">
#{campaignCode.stopDate}
</p:column>
</p:dataTable>
Anyone have any idea why this is? If I remove the scrollable attribute the table looks fine:
Incidentally, is there any way to remove the grey empty column created by a scrollable DataTable as seen in http://www.primefaces.org/showcase/ui/datatableScrolling.jsf?
EDIT: I have noticed that the ShowCase has column size fixed using the style attribute. I would rather avoid this if possible.