Task: There is a panel, with selectMany checkboxes, having 5 columns. The values of selectboxes are ordered by ascending, but they appear from left to right in columns instead of top to bottom.
Using: Primefaces Code:
<p:selectManyCheckbox id="chkbx" value=.. layout="grid" columns="5">
<p:selectItems value=.. itemValue=".." itemLabel=".."/>
</p:selectManyCheckbox>
Current screen:
[] a [] b [] c
[] d [] e [] f
[] g [] h [] i
Expected:
[] a [] d [] g
[] b [] e [] h
[] c [] f [] i
Luckily we have CSS to the rescue here. The showcase has a gridlayout example
If you take a look at the generate html, you'll see something like
Yes, a table is used here but people often forget that you can override the CSS of existing elements with CSS, so you can make the
table
,tbody
,tr
andtd
being displayed as 'flex' instead of the default display values. Just use the CSS below to make it do so.Now the trick is to play with the css
flex-direction
and assignrow
to thetbody
andcolumn
to thetr
like soWith the following result:
And if you want it applied for just one select, add an explicit class to the component and use that in the selectors.