Set p:dataTable p:column width

user489041 picture user489041 · Sep 11, 2013 · Viewed 44.4k times · Source

I am trying to set the column widths of my data table. I have looked at this question for an answer How to set width of a p:column in a p:dataTable in PrimeFaces 3.0?.

I am however trying to do something a little bit different. I only want the column to be as wide as the widest element it it is displaying. Most of my data is text.

So for example, it should not look like this

-----------------------------
| This is some text         |
-----------------------------

It should look like this

---------------------
| This is some text |
---------------------

If there are multiple rows, the coulmn should be as large as the widest element.

Answer

Maco picture Maco · Sep 11, 2013

I always use

<p:dataTable ........ tableStyle="width:auto">

And does what I think you expect your datatable to do.