Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a horizontally scrollable cell in a datatable

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="???" />
like image 602
AlanObject Avatar asked Nov 22 '12 16:11

AlanObject


1 Answers

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:

  • How do I override default PrimeFaces CSS with custom styles?
like image 112
BalusC Avatar answered Nov 15 '22 03:11

BalusC