How to partially split each row of a Primefaces datatable?

UI Components for JSF
Post Reply
JeyDeveloper
Posts: 2
Joined: 14 Oct 2020, 19:27

15 Oct 2020, 21:11

The problem I have is the following:

I have a datatable with a list of the class `Producto`, which internally consists of several fields of simple type and 2 objects of type` Proveedor`. `Categoria` and` TipoProveedor` are enums.

Code: Select all

    public class Producto {
    	
    	private int idProducto;
    	private String nombre;
    	private Categoria categoria;
    	private Proveedor proveedorUno;
    	private Proveedor proveedorDos;
    	
    }
    
    
    public class Proveedor {
    
    	private int idProveedor;
    	private TipoProveedor tipoProveedor;
    	private String nombre;
    	private BigDecimal precio;
    	
    }

My problem is that in each row of the datatable all the information must be displayed so that if a single filled 'Proveedor' comes, it will be displayed normal but if both fillings come, the part of the 'Proveedor' information is divided into 2 rows.

I had tried to do it with a datatable like this but it does not look exactly as I need:

Code: Select all

 <p:dataTable id="listadoProductos" widgetVar="listadoProductos" 
			value="#{listadoProductosBean.listadoProductos}" var="producto"
			emptyMessage="#{messages['tabla.VACIA']}">
			
			<p:column headerText="#{messages['listado.NOMBRE']}">
				<h:outputText value="#{producto.nombre}" />
			</p:column>
			<p:column headerText="#{messages['listado.CATEGORIA']}">
				<h:outputText value="#{producto.categoria.desc}" />
			</p:column>
			<p:column headerText="#{messages['listado.ID_PROVEEDOR']}" 
				rendered="#{producto.proveedorUno != null && producto.proveedorDos != null}">
				<p:panelGrid columns="1">
					<p:row>
						<h:outputText value="#{producto.proveedorUno.idProveedor}" />
					</p:row>
					<p:row>
						<h:outputText value="#{producto.proveedorDos.idProveedor}" />
					</p:row>
				</p:panelGrid>
				
			</p:column>
			<p:column headerText="#{messages['listado.ID_PROVEEDOR']}" 
				rendered="#{producto.proveedorUno != null && producto.proveedorDos == null}">
				<p:panelGrid columns="1">
					<p:row>
						<h:outputText value="#{producto.proveedorUno.idProveedor}" />
					</p:row>
				</p:panelGrid>
				
			</p:column>
			<p:column headerText="#{messages['listado.ID_PROVEEDOR']}" 
				rendered="#{producto.proveedorUno == null && producto.proveedorDos != null}">
				<p:panelGrid columns="1">
					<p:row>
						<h:outputText value="#{producto.proveedorDos.idProveedor}" />
					</p:row>
				</p:panelGrid>
				
			</p:column>
			
		</p:dataTable>

Is it possible to do what I say?

My version of Primefaces is 6.2 but I could upgrade if I can get what I want.

Many Thanks.

Melloware
Posts: 2101
Joined: 22 Apr 2013, 15:48

16 Oct 2020, 20:35

You will need to post a screenshot or mockup of what you are trying to do. I have no idea what Split Rows means?
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 8.0.3 / PF Extensions 8.0.4

JeyDeveloper
Posts: 2
Joined: 14 Oct 2020, 19:27

17 Oct 2020, 19:47

Hi Melloware.

This is an example in pure HTML with 3 registers, the first and the last have proveedorUno and proveedorDos with data, and the other register only have proveedorUno with data.

Image

Thanks

jepsar
Posts: 25
Joined: 03 Sep 2014, 11:41
Location: NL / BE
Contact:

18 Oct 2020, 14:02

PrimeFaces (Extensions) Contributor
GitHub Profile: https://github.com/jepsar

Melloware
Posts: 2101
Joined: 22 Apr 2013, 15:48

18 Oct 2020, 14:34

Stop thinking of it as "splitting rows" you need to return an object for 1 row that represents your data and then in the cells do as @JasperdeVries mentioned and use "white-space:nowrap" and "<br/>" tags to make the columns that have more than 1 value appear the way you want it.

So your row should be a Product object inside the Product object you should have Lists for ID, Name and Price since they can be multiple values.
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 8.0.3 / PF Extensions 8.0.4

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: rhare and 22 guests