JSF h:column tag fix width
I tried this way, but I couldn't get this working. With the rendered HTML, I don't see a width Attribute either for the Header or for the dataTable rows. I am using JSF 1.2 without any component libs. What could be the problem?
As such, the width of the column can be controlled using the columns. width option. This example shows the first column being set to width: 200px (note that this is not pixel perfect in a table, the browser will make some adjustments!), a width that is reflected in the fixed column.
You need to define the column visual properties on the data grid. @Roi84 if you use ASP.net, you can set the data grid column's width by changing the itemstyle properties: msdn.microsoft.com/en-us/library/…
you need to use your Lightning:DataTable inside Div Tag and Apply the SLDS Stlying. You can't control the Column width of DataTable Directly. You need to use SLDS for Div and it will show accordingly.
That linked answer honestly doesn't make sense to me. The <h:column>
as it is in the default JSF implementation does not support those attributes at all. It's far beyond me why it got 6 votes and is marked accepted. It'll be ignorance or coincidence (maybe both the questioner and answer are using a JSF implementation I am not aware of which has a renderer for <h:column>
which automagically converts all unknown attributes into real HTML attributes, but at least, the standard JSF RI / Mojarra doesn't do that, MyFaces maybe?).
That said, to style the columns separately, you need to make use of the columnClasses
attribute of the <h:dataTable>
. It accepts a commaseparated string of CSS class names which will be subsequently applied on the <td>
elemenes generated by <h:column>
.
<h:dataTable columnClasses="column1,column2,column3">
<h:column>...</h:column>
<h:column>...</h:column>
<h:column>...</h:column>
</h:dataTable>
This will end up as something like:
<table>
<tbody>
<tr>
<td class="column1">...</td>
<td class="column2">...</td>
<td class="column3">...</td>
</tr>
</tbody>
</table>
To specify the width, just apply CSS accordingly.
.column1 { width: 200px; }
.column2 { width: 100px; }
.column3 { width: 50px; }
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