Youcef Laidani Youcef Laidani - 1 year ago 290
CSS Question

DataTable PrimeFaces columns width not changes

Is there any way to specifie the same

of columns in datatable, for example this part of my
, but the width is not equal for all the columns :

<p:dataTable value="" styleClass="hide-content-names">
<p:columns value="#{managedBean.listObject}"
var="head" headerText="#{head.code}" width="20px;"/>

Width of columns

Is there any solution for that?

Thank you.

Answer Source

The best way to do this is to write some custom CSS. If you don't want to apply this to all your data tables add a class to your data table, let's say my-table.

By default PrimeFaces data tables are set to width: 100%. Override that first to auto:

.my-table.ui-datatable table { width: auto; }

Now, instead of width, set the max-width to 20px for both th and td in your table:

.my-table.ui-datatable th, .my-table.ui-datatable td { max-width: 20px; }

Using the style attribute on your column for this will also work.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download