How to make a grouping datatable with selection in primefaces? - jsf

I've tried with primefaces showcase examples, but I don't know how to make a grouping datatable with checkbox selection like this:
I've tried with subtable, p:column and p:row, but still I don't have an idea how to get same results such as if I use panelGrid.

If you want to check multiple rows with one checkbox in the 'grouped' column, that is not supported in PrimeFaces up to the 6.3-SNAPSHOT. If it is/will be supported in future releases depends on an issue being created and it getting enough support or sponsor this via paid consultancy.
Row grouping is what comes closest
<h3>Rowspan</h3>
<h:form>
<p:dataTable var="car" value="#{dtRowGroupView.cars}" sortBy="#{car.brand}">
<p:column headerText="Brand" groupRow="true">
<h:outputText value="#{car.brand}" />
</p:column>
<p:column headerText="Year">
<h:outputText value="#{car.year}" />
</p:column>
<p:column headerText="Color">
<h:outputText value="#{car.color}" />
</p:column>
<p:column headerText="Id">
<h:outputText value="#{car.id}" />
</p:column>
</p:dataTable>
</h:form>
But I've not seen this work with selection or an additional 2nd grouped row

The idea of this table was to compare the different values of each field to decide if the assumed id and name are taken as good. Here is an example:
I used ui:repeat, p:row and p:column to get this customized table:
<h:form id="stocktakingTable">
<h:panelGroup layout="block" class="col-lg-10 col-md-10 col-lg-offset-1">
<p:panelGrid>
<f:facet name="header">
<p:row>
<p:column>Ok</p:column>
<p:column>Assumed id</p:column>
<p:column>Assumed name</p:column>
<p:column>Place</p:column>
<p:column>Id</p:column>
<p:column>Name</p:column>
<p:column>Main color</p:column>
<p:column>Size</p:column>
</p:row>
</f:facet>
<ui:repeat value="#{oneCtrl.stocktakingList}" var="stocktaking">
<p:row>
<p:column rowspan="4">
<p:selectBooleanCheckbox value="#{stocktaking.ok}" disabled="#{stocktaking.ok}" valueChangeListener="#{oneCtrl.updateStocktaking(stocktaking)}">
<p:ajax update=":#{p:component('stocktakingTable')}"/>
</p:selectBooleanCheckbox>
</p:column>
<p:column rowspan="4" style="font-weight: #{stocktaking.ok ? 'normal' : 'bold'}">#{stocktaking.assumedId}</p:column>
<p:column rowspan="4" style="font-weight: #{stocktaking.ok ? 'normal' : 'bold'}">#{stocktaking.assumedName}</p:column>
<p:column style="font-style: italic">Real Stocktaking</p:column>
<p:column style="color: #{oneCtrl.AssignedColors.get(stocktaking.realId)}">#{stocktaking.realId}</p:column>
<p:column style="color: #{oneCtrl.AssignedColors.get(stocktaking.realName)}">#{stocktaking.realName}</p:column>
<p:column style="color: #{oneCtrl.AssignedColors.get(stocktaking.realColor)}">#{stocktaking.realColor}</p:column>
<p:column style="color: #{oneCtrl.AssignedColors.get(stocktaking.realSize)}">#{stocktaking.realSize}</p:column>
</p:row>
<p:row>
<p:column style="font-style: italic">Calculated stocktaking</p:column>
<p:column style="color: #{oneCtrl.AssignedColors.get(stocktaking.calculatedId)}">#{stocktaking.calculatedId}</p:column>
<p:column style="color: #{oneCtrl.AssignedColors.get(stocktaking.calculatedName)}">#{stocktaking.calculatedName}</p:column>
<p:column style="color: #{oneCtrl.AssignedColors.get(stocktaking.calculatedColor)}">#{stocktaking.calculatedColor}</p:column>
<p:column style="color: #{oneCtrl.AssignedColors.get(stocktaking.calculatedSize)}">#{baseCtrl.calculatedSize}</p:column>
</p:row>
<p:row>
<p:column style="font-style: italic">Shop web page</p:column>
<p:column style="color: #{oneCtrl.AssignedColors.get(stocktaking.shopId)}">#{stocktaking.shopId}</p:column>
<p:column style="color: #{oneCtrl.AssignedColors.get(stocktaking.shopName)}">#{stocktaking.shopName}</p:column>
<p:column style="color: #{oneCtrl.AssignedColors.get(stocktaking.shopColor)}">#{stocktaking.shopColor}</p:column>
<p:column style="color: #{oneCtrl.AssignedColors.get(stocktaking.shopSize)}">#{stocktaking.shopSize}</p:column>
</p:row>
<p:row>
<p:column style="font-style: italic">Online shop web page</p:column>
<p:column style="color: #{oneCtrl.AssignedColors.get(stocktaking.onlineId)}">#{stocktaking.onlineId}</p:column>
<p:column style="color: #{oneCtrl.AssignedColors.get(stocktaking.onlineName)}">#{stocktaking.onlineName}</p:column>
<p:column style="color: #{oneCtrl.AssignedColors.get(stocktaking.onlineColor)}">#{stocktaking.onlineColor}</p:column>
<p:column style="color: #{oneCtrl.AssignedColors.get(stocktaking.onlineSize)}">#{stocktaking.onlineSize}</p:column>
</p:row>
<p:row>
<p:column colspan="8" styleClass="ui-widget-header"/>
</p:row>
</ui:repeat>
</p:panelGrid>
</h:panelGroup>
</h:form>
I’m sorry if I wasn’t clear enough at first :'(

Related

How can I use primefaces datatable?

I have class Task and class File which have List<Task> tasks as attribute.
How can I display details of tasks in datatable which contains details of file?
<p:dataTable var="files" value="#{fileMB.files}" id="file" >
<p:column style="width:35px">
<p:rowToggler />
</p:column>
<p:column headerText="FileName" style="text-align: center;"
sortBy="#{files.fileName}" filterBy="#{files.fileName}">
<h:outputText value="#{files.fileName}" />
</p:column>
<p:column headerText="TaskName" style="text-align: center;">
<h:outputText value="#{file.tasks.taskName}" />
</p:column>
</p:dataTable>
An Error Occurred:For input string: "taskName"
pb resolved : I use "get":
<p:column headerText="TaskName" style="text-align: center;">
<h:outputText value="${files.tasks.get(0).taskName}"/>
</p:column>

SummaryRow in p:dataTable not working

I am trying to show a total value on my dataTable, my code is similar to the primefaces showcase DataTable - SummaryRow and still not working.
<p:dataTable id="dtCaixa" var="list" value="#{caixaMB.list}" paginator="true" rows="7"
paginatorPosition="bottom" rowsPerPageTemplate="10,15,20" liveScroll="true"
paginatorAlwaysVisible="false" emptyMessage="Nenhuma entrada!" liveResize="true">
<p:column headerText="Nome" sortBy="#{list.produtoFK.nome}" style="width:15%;">
<h:outputText value="#{list.produtoFK.nome}" />
</p:column>
<p:column headerText="Funcionário" sortBy="#{list.funcionarioFK.nome}">
<h:outputText value="#{list.funcionarioFK.nome}" />
</p:column>
<p:column headerText="Quantidade" sortBy="#{list.quantidade}">
<h:outputText value="#{list.quantidade}" />
</p:column>
<p:column headerText="Preço" >
<h:outputText value="#{list.produtoFK.preco}" rendered="#{not empty list.produtoFK}">
<f:convertNumber pattern="R$ #0.00" locale="pt_BR"/>
</h:outputText>
</p:column>
<p:column headerText="Total" sortBy="#{list.total}" >
<h:outputText value="#{list.total}" >
<f:convertNumber pattern="R$ #0.00" locale="pt_BR"/>
</h:outputText>
</p:column>
<p:column headerText="Remover" class="centered">
<p:commandButton icon="ui-icon-trash" title="excluir" onclick="PF('confirmaExclusao').show();">
<f:setPropertyActionListener target="#{caixaMB.itemSelecionado}" value="#{list}" />
</p:commandButton>
</p:column>
<p:summaryRow>
<p:column colspan="3" style="text-align:right">
<h:outputText value="Total:" />
</p:column>
<p:column>
<h:outputText value="#{caixaMB.total}">
</h:outputText>
</p:column>
</p:summaryRow>
</p:dataTable>
Does anybody have any idea why is this happening?
You need to sort the dataTable using at least one column if you want to use summaryRow. Check the Primefaces documentation.
E.g. put the attribute sortBy="#{myList.myOrderValue}" on the <p:datatable> tag.
I think what you're trying to achieve is the overall total of the column showing up at the bottom. I was caught out by the summaryRow function too, until I realised it was a grouping function and not a totalling summary. What I did you get around this was for the last column I added some footerText. You will have to calculate your totals manually (iterate over your dataset etc), then you can use something like:
<p:column style="text-align: right" footerText="$ #{invoicesbean.total}">
<f:facet name="header">
<h:outputText value="Amount" />
</f:facet>
........ etc
This worked well for me but YMMV!

p:columnGroup in p:pataTable does not show headerText

I try to make a data table group of PrimeFaces. All goes well. The number of columns is correct, colspan= "#{asignaturaController.nombrePruebasEscritas1.size()} but the name of each test does not show and the object pointed to is full. I tried everything.
Anyone have any idea?
This is my result.
but I need the names of "Pruebas" over the "pruebas"
<h:form id="form-tablapruebasescritas1"
renderer="#{asignaturaController.nombrePruebasEscritas1.size() != 0}">
<p:dataTable var="player"
value="#{asignaturaController.alumnos}"
id="tablapruebasescritas1"
style="margin-top:40px"
sortOrder="ascending">
<f:facet name="header">
1ª Evaluacion
</f:facet>
<p:columnGroup type="header">
<p:row>
<p:column rowspan="2" headerText="Alumno" />
<p:column colspan="#{asignaturaController.nombrePruebasEscritas1.size()}"
headerText="Pruebas" />
</p:row>
<p:row>
<ui:repeat value="#{asignaturaController.nombrePruebasEscritas1}"
var="yea">
<p:column headerText="#{yea}" />
</ui:repeat>
</p:row>
</p:columnGroup>
<p:column>
<h:outputText value="#{player.nombre}" />
</p:column>
<p:columns value="#{asignaturaController.nombrePruebasEscritas1}"
var="year">
<h:outputText value="#{player.getNotaParaTabla(year)}" />
</p:columns>
</p:dataTable>
</h:form>

How to visualize PanelGrid components inside DataTable

I am trying to create a DataTable (because of pagination) with PanelGrid like this.
My code for the grid is taken from PrimeFaces website:
<p:panelGrid style="margin-top:20px">
<f:facet name="header">
<p:row>
<p:column colspan="7">1995-96 NBA Playoffs</p:column>
</p:row>
<p:row>
<p:column colspan="2">Conf. Semifinals</p:column>
<p:column colspan="2">Conf. Finals</p:column>
<p:column colspan="2">NBA Finals</p:column>
<p:column>Champion</p:column>
</p:row>
</f:facet>
<p:row>
<p:column style="font-weight: bold;">Seattle</p:column>
<p:column style="font-weight: bold;">4</p:column>
<p:column rowspan="2" style="font-weight: bold;">Seattle</p:column>
<p:column rowspan="2" style="font-weight: bold;">4</p:column>
<p:column rowspan="5">Seattle</p:column>
<p:column rowspan="5">2</p:column>
<p:column rowspan="11" style="font-weight: bold;">Chicago</p:column>
</p:row>
<p:row>
<p:column>Houston</p:column>
<p:column>0</p:column>
</p:row>
</p:panelGrid>
When i put the code for the grid between DataTable tags, it just show the header and pagination line. Some idea how to make such PanelGrids with pagination?
You don't need p:panelGrid for that. You can use p:dataTable and p:row with p:column rowspan="2" and p:column colspan="2" like you have in your code. In case if table is more complicated use p:subTable. Example of subtable is here.

IF statement does not work inside Primefaces DataTable

I want to show a row only if I have data for it. The code which i have is:
<p:dataTable id="comments" var="comment"
value="#{agencyBean.getCommentByAgency(agencyBean.tAgency)}"
paginator="true" >
<p:column>
#{comment.author.name}
</p:column>
<p:column>
<c:if test="${not empty comment.positiveComment}">
<p:row>
<p:column>
<p:graphicImage library="images" name="positive.png" />
</p:column>
<p:column> #{comment.positiveComment} </p:column>
</p:row>
<br />
</c:if>
</p:column>
</p:dataTable>
But nevertheless I have data, the row is not shown. How can i implement this logic? Thanks!
Try to place the condition expression in the <p:row>'s tag itself, by using its rendered attribute :
<p:column>
<p:row rendered="#{not empty comment.positiveComment}">
<p:column>
<p:graphicImage library="images" name="positive.png" />
</p:column>
<p:column> #{comment.positiveComment} </p:column>
</p:row>
<br />
</p:column>

Resources