How can I change column width of panel grid in PrimeFaces - jsf

I am working with Java EE and PrimeFaces. How can I change the column width of a panel grid in PrimeFaces?
Is there an example ?

You can qualify your columns inside the panelGrid using columnClasses. The following code sets different width and stick the cells content aligned to the top-side.
<h:panelGrid columns="2" style="width: 100%" columnClasses="forty-percent top-alignment, sixty-percent top-alignment">
.forty-percent {
width: 40%;
}
.sixty-percent {
width: 60%;
}
.top-alignment {
vertical-align: top;
}

I had a similar problem and here is my solution:
<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>
So as you can see, the main difference is that you do not define columns attribute in p:panelGrid. In header and footer you have to use p:row and p:column, and in my case I also have to use colspan=2 since in body we have 2 columns.
Hope this helps ;)

Have you considered the style attribute ?
Example :
<p:panelGrid columns="2" style="width: 50px">
Otherwise, for columns :
<p:column style="width:50px">
Refer to this thread : how can I adjust width of <p:column> in <p:panelGrid>?

Related

How to block a single datatable cell in primefaces with blockUI

I'm creating a datatable with some some dynamically generated columns. In each of the cells of those columns, there's a button to refresh the data of that specific cell.
What I want is that the cell is blocked when the button on that cell is pressed.
Sample code:
<p:dataTable id="table" var="tableVar" value="#{tableValues}">
<p:columns id="column" var="columnVar" value="#{columnValues}">
<f:facet name="header">
<h:outputText value ="#{columnVar}"/>
</f:facet>
<h:outputText value="Some Text"/>
<p:commandButton value="Button Text"
id="button"
update="table"
actionListener="#{some.method()}"/>
<p:blockUI block="?????" trigger="button">
<p:graphicImage name="loading.gif"/>
</p:blockUI>
</p:columns>
</p:dataTable>
I don't know what should go in the block parameter to only block a cell. I also tried to just block="column", but even that wasn't blocking the column as I expected, instead it was just displaying the loading gif near the button but not blocking anything.
I have seen this question How update just specific cell in primefaces dataTable where the answers say it's not possible to specify a single cell, but it's from 2012, and the answers mention that it might get fixed on a later version.
After playing a bit, I found a solution.
You can define a <p:outputpanel id="cell"></p:outputpanel> surrounding the content of the cell, and then block it with block="cell" in the blockUI component.
The result would be something like:
<p:dataTable id="table" var="tableVar" value="#{tableValues}">
<p:columns id="column" var="columnVar" value="#{columnValues}">
<f:facet name="header">
<h:outputText value ="#{columnVar}"/>
</f:facet>
<p:outputpanel id="cell">
<h:outputText value="Some Text"/>
<p:commandButton value="Button Text"
id="button"
update="table"
actionListener="#{some.method()}"/>
<p:blockUI block="cell" trigger="button">
<p:graphicImage name="loading.gif"/>
</p:blockUI>
</p:outputpanel>
</p:columns>
</p:dataTable>

Submit in a fetch mode collapsed rows

I have this datatable:
<p:dataTable id="necesidades"
value="#{registrarAccionDosBean.accionDos.necesidadesConTema}"
rendered="#{not empty registrarAccionDosBean.accionDos.necesidadesConTema}"
var="necesidad"
rowKey="#{necesidad.idNecesidad}">
<p:column style="width:16px">
<p:rowToggler />
</p:column>
<p:rowExpansion>
<h:panelGroup id="grupoTema">
<h:panelGroup id="edicion" rendered="#{necesidad.tema.idTema ne null}">
<p:row>
<p:column >
<h:outputLabel value="#{etiq.lbl_comunes_requerido} #{etiq.etiqueta_checkbox_transparenciasFocalizadas}" styleClass="textoAcciones"/>
</p:column>
<p:column >
<!-- Nested data table -->
<p:dataTable id="transparenciasInplace"
var="transparencias"
value="#{registrarAccionDosBean.transparenciasFocalizadas}"
selection="#{necesidad.tema.transparenciasFocalizadas}"
rowKey="#{transparencias.idTf}">
<f:facet name="header">
Objetives
</f:facet>
<p:column selectionMode="multiple" style="width:16px;text-align:center"/>
<p:column>
<h:outputLabel value="#{transparencias.descripcion}" styleClass="textoAccionesSmall"/>
</p:column>
</p:dataTable>
</p:column>
</p:row>
</h:panelGroup>
</h:panelGroup>
</p:rowExpansion>
</p:dataTable>
I have n rows collapsed with information inside of each of them, this information was persisted in different times and days, so I need to save some information plus the n rows as a whole, the problem is that the rows are collapsed when is show on screen and I want to be in that way because a can have a lot rows on screen and if I show them expanded it will be hard to read, but when I send it through a command button the table inside my collapsed row are setting null, I need to expand each of them in order to properly send all the information.
So I want to send the information collapsed but in some way force to fetch the information inside of each of them
I am getting the information from the database right, because there I just fetch my query and get the information right, so my problem is on my jsf page I think

Primefaces dataTable reRender column is not working

I am using Primefaces 5.1 in my page I use dataTable inside another dataTable.In add button press add new bean for salList and check salList not null to rendered header column.But sal column not rendered.
<p:dataTable id="mainTable" value="#{employee.employeeList}" var="emp" ..>
<p:columnGroup type="header">
<p:row >
<p:column headerText="Name"/>
</p:column headerText="value" **rendered="#{emp.salList ne null and not empty emp.salList}**/>
....
<p:column>
<f:facet name="header"><p:commandButton value="add button" action="#{employee.addButton}" update="mainTable"/>
</f:facet>
</p:column>
</p:row>
</p:columnGroup>
<p:column>
<p:dataTable value="#{emp.salList}" var="sp">
<p:column></p:column>
..
</p:dataTable>
</p:column>
</p:dataTable>
My doubt is when I press add button to add new list salList bean and it add new bean and show component in inside dataTable.But in header column salary column is not rendered i.e header column not updated it will not rendered the specify header column.

Display row from panle grid on new line

I am using a datagrid to display row dynamically from panelgrid. It works fine except the layout is not good. It displays the following row side by side instead on new line. Anyone know how to display a new row on a new line ? I tried to use <br/> tag, but it's not working.
<p:dataGrid style="border:10px;" value="#{TestComponent.list}" var="x">
<p:panelGrid style="width:1250px;">
<p:row>
<p:column colspan="1">1.1</p:column>
<p:column colspan="2">
<h:outputText value="#{x.Description}" />
</p:column>
<p:column colspan="4">
<h:inputTextarea rows="10" cols="40"
value="#{x.Justification}" required="false" label="Justification" />
</p:column>
</p:row>
</p:panelGrid>
<br/>
</p:dataGrid>
If you want to create a new line, you must create a new <p:row> tag.
Example:
<p:panelGrid>
<p:row>
<p:column>Row 1/Column 1</p:column>
<p:column>Row 1/Column 2</p:column>
</p:row>
<p:row>
<p:column>Row 2/Column 1</p:column>
<p:column>Row 2/Column 2</p:column>
</p:row>
</p:panelGrid>
Manage to do it. It have to specify the number of columns in my datagrid.
It's a combination of things done wrong. The datagrid by itself puts childeren next to eachother in colums (default = 3 , see the docs http://www.primefaces.org/showcase/ui/data/dataGrid.xhtml). So 3 panelgrids next to eachother (so three rows next to eachother). Setting the columns to 1 will makr it work. Additionally, a colspan does nothing if there are not multiple rows like in the example #pellizon mentiones.

Panel grid layout in PrimeFaces

I want a layout of <p:panelGrid> (or <h:panelGrid>) as shown in the following snap shot.
The following code,
<p:panelGrid style="width: 100%;">
<p:row>
<p:column rowspan="9">a</p:column>
<p:column rowspan="7">b</p:column>
<p:column>c</p:column>
</p:row>
<p:row><p:column>d</p:column></p:row>
<p:row><p:column>e</p:column></p:row>
<p:row><p:column>f</p:column></p:row>
<p:row><p:column>g</p:column></p:row>
<p:row><p:column>h</p:column></p:row>
<p:row><p:column>i</p:column></p:row>
<p:row><p:column>j</p:column></p:row>
<p:row><p:column>k</p:column></p:row>
</p:panelGrid>
shows the layout as shown in the following snap shot.
How can I achieve the layout as shown in first snap shot?
<p:panelGrid style="width: 100%;">
<p:row>
<p:column rowspan="7">a</p:column>
<p:column rowspan="5">b</p:column>
<p:column>e</p:column>
</p:row>
<p:row>
<p:column>f</p:column>
</p:row>
<p:row>
<p:column>g</p:column>
</p:row>
<p:row>
<p:column>h</p:column>
</p:row>
<p:row>
<p:column>i</p:column>
</p:row>
<p:row>
<p:column>c</p:column>
<p:column>j</p:column>
</p:row>
<p:row>
<p:column>d</p:column>
<p:column>k</p:column>
</p:row>
</p:panelGrid>
Explanation:
Each row will try to place itself under the previous row where there is space for it (where a column is not spanning over multiple rows).
So after the first row: the next rows will be placed in the following positions:
But since you want the 6th and 7th row to have 2 columns, you need to add a second column to them.
Hopefully this clears it up a little.

Resources