如何在PrimeFaces中更改面板网格的列宽

And*_*ida 16 jsf primefaces

我正在使用Java EE和PrimeFaces.如何在PrimeFaces中更改面板网格的列宽?有一个例子吗?

Ivá*_*ván 29

您可以使用columnClasses在panelGrid中限定列.以下代码设置不同的宽度,并将单元格内容与顶部对齐.

<h:panelGrid columns="2" style="width: 100%" columnClasses="forty-percent top-alignment, sixty-percent top-alignment">
Run Code Online (Sandbox Code Playgroud)
.forty-percent {
     width: 40%;
}

.sixty-percent {
     width: 60%;
}

.top-alignment {
     vertical-align: top;
}
Run Code Online (Sandbox Code Playgroud)

  • 如果您有多列,您还可以指定没有自定义css的列的宽度比,例如`<p:panelGrid columns ="4"columnClasses ="ui-grid-col-2,ui-grid-col-4,ui- grid-col-2,ui-grid-col-4"layout ="grid"> ... </ p:panelGrid>` (5认同)

Mar*_*vic 11

我有类似的问题,这是我的解决方案:

<p:panelGrid style="width:100%"> # notice that I do not define columns attribute in p:panelGrid!!
    <f:facet name="header"> # header
        <p:row> # p:row and p:column are obligatory to use since we do not define columns attribute!
            <p:column colspan="2"> # here I use colspan=2, coz I have 2 columns in the body
                Title
            </p:column>
        </p:row>
    </f:facet>

    <p:row>
        <p:column style="width:150px"> # define width of a column
            Column 1 content
        </p:column>
        <p:column> # column 2 will fill the rest of the space
            Column 2 content
        </p:column>
    </p:row>

    <f:facet name="footer"> # similar as header
        <p:row>
            <p:column colspan="2">
                Footer content
            </p:column>
        </p:row>
    </f:facet>
</p:panelGrid>
Run Code Online (Sandbox Code Playgroud)

如您所见,主要区别在于您没有p:panelGrid中定义columns属性.在页眉和页脚中你必须使用p:rowp:列,在我的情况下我还必须使用colspan = 2,因为在正文中我们有2列.

希望这可以帮助 ;)


Akh*_*oes 7

你考虑过style属性了吗?示例:

<p:panelGrid columns="2" style="width: 50px">
Run Code Online (Sandbox Code Playgroud)

否则,对于列:

<p:column style="width:50px">
Run Code Online (Sandbox Code Playgroud)

请参阅此主题:如何在<p:panelGrid>中调整<p:column>的宽度?