Primefaces selectManyCheckbox布局在列中从上到下

use*_*379 6 layout jsf orientation primefaces selectmanycheckbox

任务:有一个带有selectMany复选框的面板,该面板有5列。选择框的值按升序排列,但它们在列中从左到右而不是从上到下显示。

使用:Primefaces代码:

<p:selectManyCheckbox id="chkbx" value=.. layout="grid" columns="5">
<p:selectItems value=.. itemValue=".." itemLabel=".."/>
</p:selectManyCheckbox>
Run Code Online (Sandbox Code Playgroud)

当前屏幕:

[] a    [] b    [] c  

[] d    [] e    [] f

[] g    [] h    [] i
Run Code Online (Sandbox Code Playgroud)

预期:

[] a    [] d    [] g  

[] b    [] e    [] h

[] c    [] f    [] i
Run Code Online (Sandbox Code Playgroud)

Kuk*_*tje 5

幸运的是,我们这里有CSS可以解救。展示柜中有一个网格布局示例

现有的网格布局

如果您查看生成html,您会看到类似

<table id="j_idt701:grid" role="presentation" class="ui-selectmanycheckbox ui-widget">
    <tbody>
        <tr>
            <td>
                <div class="ui-chkbox ui-widget">
                    <div class="ui-helper-hidden-accessible">
                        <input id="j_idt701:grid:0" name="j_idt701:grid" type="checkbox" value="Miami" data-p-hl="manychkbox" data-p-grouped="true">
                    </div>
                    <div class="ui-chkbox-box ui-widget ui-corner-all ui-state-default">
                        <span class="ui-chkbox-icon ui-icon ui-icon-blank ui-c" />
                    </div>
                </div>
                <label for="j_idt701:grid:0">Miami</label>
            </td>
            <td>
                <div class="ui-chkbox ui-widget">
                    <div class="ui-helper-hidden-accessible">
                        <input id="j_idt701:grid:1" name="j_idt701:grid" type="checkbox" value="London" data-p-hl="manychkbox" data-p-grouped="true">
                    </div>
                    <div class="ui-chkbox-box ui-widget ui-corner-all ui-state-default">
                        <span class="ui-chkbox-icon ui-icon ui-icon-blank ui-c"/>
                    </div>
                </div>
                <label for="j_idt701:grid:1">London</label>
            </td>
            <td>
                <div class="ui-chkbox ui-widget">
                    <div class="ui-helper-hidden-accessible">
                        <input id="j_idt701:grid:2" name="j_idt701:grid" type="checkbox" value="Paris" data-p-hl="manychkbox" data-p-grouped="true">
                    </div>
                    <div class="ui-chkbox-box ui-widget ui-corner-all ui-state-default">
                        <span class="ui-chkbox-icon ui-icon ui-icon-blank ui-c"/>
                    </div>
                </div>
                <label for="j_idt701:grid:2">Paris</label>
            </td>
        </tr>
        <tr>...</tr>
        <tr>...</tr>
    </tbody>
</table>
Run Code Online (Sandbox Code Playgroud)

是的,一台用在这里,但人们常常忘了,你可以重写与CSS现有元素的CSS,这样可以使tabletbodytrtd被显示为“柔性”,而不是默认的显示值。只需使用下面的CSS即可。

table.ui-selectmanycheckbox, table.ui-selectmanycheckbox tbody ,table.ui-selectmanycheckbox tr, table.ui-selectmanycheckbox td{
    display: flex;
}
Run Code Online (Sandbox Code Playgroud)

现在的诀窍是使用CSS flex-direction并分配rowtbodycolumntr这样

table.ui-selectmanycheckbox tbody{
    flex-direction: row;
}

table.ui-selectmanycheckbox tr{
    flex-direction: column;
}
Run Code Online (Sandbox Code Playgroud)

结果如下:

应用flex CSS后的结果

如果只希望将其应用于一个选择,则向该组件添加一个显式类,并在选择器中使用它。