This is with PrimeFaces, but I think the question applies equally to a standard JSF datatable.
I have a datatable column where the entry is being word wrapped because the content can be quite long. To make the display more readable, I would prefer the content to be not wrapped, but instead provide horizontal scrolling to view whatever content doesn't appear by default.
I am sure this a simple CSS modification but my proficiency is very low.
<p:dataTable ... >
<p:column headerText="Book Title">
<h:outputText value="#{book.title}" style="???" />
This is only possible when the text is enclosed in a block-level HTML element with a definied width and text-wrapping disabled and the element in question has the CSS property overflow:scroll
or at least overflow-x:scroll
definied.
So, in plain HTML terms, that would basically be the following approach:
<div style="width: 200px; white-space: nowrap; overflow-x: scroll;">
Some really really lengthy book title about a really really lengthy book.
</div>
In PrimeFaces <p:column>
terms, that would be:
<p:column styleClass="scrollableCell">
#{book.title}
</p:column>
with
.ui-datatable td.scrollableCell div.ui-dt-c {
width: 200px;
white-space: nowrap;
overflow-x: scroll;
}
Note that you don't need to bring in any div, the <p:column>
already does that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With