7

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="???" />
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
AlanObject
  • 9,613
  • 19
  • 86
  • 142

1 Answers1

8

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.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • well that worked just fine thanks once again. Someday I am going to learn CSS. This should probably be a standard feature of PF. – AlanObject Nov 22 '12 at 18:31