Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the width for the dataTable rendered column in JSF?

Tags:

jsf

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?

like image 547
gekrish Avatar asked Jul 27 '10 13:07

gekrish


People also ask

How to give width to column in DataTable?

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.

How to set DataTable column width in c#?

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/…

How do you set column width in lightning DataTable?

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.


1 Answers

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; }
like image 111
BalusC Avatar answered Oct 16 '22 16:10

BalusC