Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #6409 - Datatable: ColumnGroup refactoring #9872

Draft
wants to merge 31 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion primefaces-showcase/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@
<jsf.project.stage>Development</jsf.project.stage>
</properties>
<build>
<defaultGoal>clean jetty:run</defaultGoal>
<defaultGoal>jetty:run</defaultGoal>
</build>
</profile>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,28 @@
*/
package org.primefaces.showcase.view.data.datatable;

import jakarta.faces.view.ViewScoped;
import org.primefaces.showcase.domain.Player;
import org.primefaces.showcase.domain.Sale;

import jakarta.annotation.PostConstruct;
import jakarta.inject.Named;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import jakarta.annotation.PostConstruct;
import jakarta.faces.view.ViewScoped;
import jakarta.inject.Named;
import org.primefaces.showcase.domain.Player;
import org.primefaces.showcase.domain.Sale;

@Named("dtGroupView")
@ViewScoped
public class GroupView implements Serializable {

private static final String[] MANUFACTORS;
private static final String[] PLAYER_NAMES;

private boolean frozenColumns = false;
private int nbFrozenColumns = 0;

private List<Sale> sales;
private Integer lastYearTotal;
private Integer thisYearTotal;
Expand Down Expand Up @@ -144,4 +147,17 @@ private Map<Integer, Integer> generateRandomGoalStatsData() {
private int getRandomGoals() {
return (int) (Math.random() * 50);
}

public boolean isFrozenColumns() {
return frozenColumns;
}

public void setFrozenColumns(boolean frozenColumns) {
this.nbFrozenColumns = frozenColumns ? 1 : 0;
this.frozenColumns = frozenColumns;
}

public int getNbFrozenColumns() {
return nbFrozenColumns;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,62 +75,38 @@
<p:dataTable var="sale" value="#{dtGroupView.sales}" resizableColumns="true" resizeMode="expand"
showGridlines="true">

<p:columnGroup type="header">
<p:row>
<p:column rowspan="3" headerText="Product"/>
<p:column colspan="4" headerText="Sale Rate"/>
</p:row>
<p:row>
<p:column colspan="2" headerText="Sales"/>
<p:column colspan="2" headerText="Profit"/>
</p:row>
<p:row>
<p:column headerText="Last Year"/>
<p:column headerText="This Year"/>
<p:column headerText="Last Year"/>
<p:column headerText="This Year"/>
</p:row>
<f:facet name="header">
<h:outputText value="Product Sales"/>
</f:facet>

<p:column headerText="Product" field="manufacturer"/>

<p:columnGroup headerText="Sale Rate">
<p:columnGroup headerText="Sales">
<p:column headerText="Last Year" field="lastYearSale"/>
<p:column headerText="This Year" field="thisYearSale"/>
</p:columnGroup>
<p:columnGroup headerText="Profit">
<p:column headerText="Last Year" field="lastYearProfit"/>
<p:column headerText="This Year" field="thisYearProfit"/>
</p:columnGroup>
</p:columnGroup>

<p:column>
<h:outputText value="#{sale.manufacturer}"/>
</p:column>
<p:column>
<h:outputText value="#{sale.lastYearProfit}%"/>
</p:column>
<p:column>
<h:outputText value="#{sale.thisYearProfit}%"/>
</p:column>
<p:column>
<h:outputText value="#{sale.lastYearSale}">
<f:convertNumber type="currency" currencySymbol="$"/>
</h:outputText>
</p:column>
<p:column>
<h:outputText value="#{sale.thisYearSale}">
<f:convertNumber type="currency" currencySymbol="$"/>
</h:outputText>
</p:column>

<p:columnGroup type="footer">
<f:facet name="tfooter">
<p:row>
<p:column colspan="3" style="text-align:right" footerText="Totals:"/>
<p:column colspan="3" style="text-align:right">Totals:</p:column>
<p:column>
<f:facet name="footer">
<h:outputText value="#{dtGroupView.lastYearTotal}">
<f:convertNumber type="currency" currencySymbol="$"/>
</h:outputText>
</f:facet>
<h:outputText value="#{dtGroupView.lastYearTotal}">
<f:convertNumber type="currency" currencySymbol="$"/>
</h:outputText>
</p:column>
<p:column>
<f:facet name="footer">
<h:outputText value="#{dtGroupView.thisYearTotal}">
<f:convertNumber type="currency" currencySymbol="$"/>
</h:outputText>
</f:facet>
<h:outputText value="#{dtGroupView.thisYearTotal}">
<f:convertNumber type="currency" currencySymbol="$"/>
</h:outputText>
</p:column>
</p:row>
</p:columnGroup>
</f:facet>
</p:dataTable>
</div>
</h:form>
Expand Down
145 changes: 65 additions & 80 deletions primefaces-showcase/src/main/webapp/ui/data/datatable/group.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@
xmlns:f="jakarta.faces.core"
xmlns:p="primefaces" template="/WEB-INF/template.xhtml">

<ui:define name="head">
<style>
.ui-datatable-frozenlayout-left {
width: 20%;
}

.ui-datatable-frozenlayout-right {
width: 80%;
}
</style>
</ui:define>

<ui:define name="title">
DataTable <span class="subitem">Group</span>
</ui:define>
Expand All @@ -17,112 +29,85 @@

<ui:define name="implementation">
<div class="card">
<h:form>
<h:form id="form">
<div class="flex justify-content-between">
<div>
</div>
<div>
<p:commandButton value="XLSX" styleClass="mr-2 mb-2" >
<p:dataExporter type="xlsxstream" target="tblSales tblPlayers" fileName="grouped"/>
</p:commandButton>

<p:commandButton value="PDF" styleClass="mr-2 mb-2" >
<p:dataExporter type="pdf" target="tblSales tblPlayers" fileName="grouped"/>
</p:commandButton>
</div>
<div>
Frozen columns
<p:selectBooleanButton value="#{dtGroupView.frozenColumns}">
<p:ajax update=":form"/>
</p:selectBooleanButton>
</div>
<div>
<p:commandButton value="XLSX" styleClass="mr-2 mb-2">
<p:dataExporter type="xlsxstream" target="tblSales tblPlayers" fileName="grouped"/>
</p:commandButton>

<p:commandButton value="PDF" styleClass="mr-2 mb-2">
<p:dataExporter type="pdf" target="tblSales tblPlayers" fileName="grouped"/>
</p:commandButton>
</div>
</div>
<p:dataTable id="tblSales" var="sale" value="#{dtGroupView.sales}">

<p:dataTable id="tblSales" var="sale" value="#{dtGroupView.sales}" columnGroupLegacyEnabled="false"
scrollable="#{dtGroupView.frozenColumns}" frozenColumns="#{dtGroupView.nbFrozenColumns}"
scrollWidth="500">
<f:facet name="header">
<h:outputText value="Product Sales"/>
</f:facet>

<p:columnGroup type="header">
<p:row>
<p:column rowspan="3" headerText="Product"/>
<p:column colspan="4" headerText="Sale Rate"/>
</p:row>
<p:row>
<p:column colspan="2" headerText="Sales"/>
<p:column colspan="2" headerText="Profit"/>
</p:row>
<p:row>
<p:column headerText="Last Year"/>
<p:column headerText="This Year"/>
<p:column headerText="Last Year"/>
<p:column headerText="This Year"/>
</p:row>
<p:column headerText="Product" field="manufacturer"
footerText="Table footer (tfoot) using column footer facet"/>

<p:columnGroup headerText="Sale Rate">
<p:columnGroup headerText="Sales">
<p:column headerText="Last Year" field="lastYearSale" footerText="A"/>
<p:column headerText="This Year" field="thisYearSale" footerText="B"/>
</p:columnGroup>
<p:columnGroup headerText="Profit">
<p:column headerText="Last Year" field="lastYearProfit" footerText="C"/>
<p:column headerText="This Year" field="thisYearProfit" footerText="D"/>
</p:columnGroup>
</p:columnGroup>

<p:column>
<h:outputText value="#{sale.manufacturer}"/>
</p:column>
<p:column>
<h:outputText value="#{sale.lastYearProfit}%"/>
</p:column>
<p:column>
<h:outputText value="#{sale.thisYearProfit}%"/>
</p:column>
<p:column>
<h:outputText value="#{sale.lastYearSale}">
<f:convertNumber type="currency" />
</h:outputText>
</p:column>
<p:column>
<h:outputText value="#{sale.thisYearSale}">
<f:convertNumber type="currency" />
</h:outputText>
</p:column>

<p:columnGroup type="footer">
<p:row>
<p:column colspan="3" style="text-align:right" footerText="Totals:"/>
<f:facet name="tfooter">
<p:row >
<p:column>Table footer (tfoot) using table tfooter</p:column>
<p:column colspan="2" style="text-align:right">Totals:</p:column>
<p:column>
<f:facet name="footer">
<h:outputText value="#{dtGroupView.lastYearTotal}">
<f:convertNumber type="currency" currencySymbol="$"/>
</h:outputText>
</f:facet>
<h:outputText value="#{dtGroupView.lastYearTotal}">
<f:convertNumber type="currency" currencySymbol="$"/>
</h:outputText>
</p:column>
<p:column>
<f:facet name="footer">
<h:outputText value="#{dtGroupView.thisYearTotal}">
<f:convertNumber type="currency" currencySymbol="$"/>
</h:outputText>
</f:facet>
<h:outputText value="#{dtGroupView.thisYearTotal}">
<f:convertNumber type="currency" currencySymbol="$"/>
</h:outputText>
</p:column>
</p:row>
</p:columnGroup>
</f:facet>

<f:facet name="footer">
<h:outputText value="Data between 2013-2014"/>
</f:facet>
</p:dataTable>

<p:dataTable id="tblPlayers" var="player" value="#{dtGroupView.players}" style="margin-top:40px">
<p:dataTable id="tblPlayers" var="player" value="#{dtGroupView.players}" style="margin-top:40px"
columnGroupLegacyEnabled="false" scrollable="#{dtGroupView.frozenColumns}" frozenColumns="#{dtGroupView.nbFrozenColumns}"
scrollWidth="500">
<f:facet name="header">
<h:outputText value="Dynamic Columns"/>
</f:facet>

<p:columnGroup type="header">
<p:row>
<p:column rowspan="2" headerText="Player"/>
<p:column colspan="#{dtGroupView.yearCount}" headerText="Goals"/>
</p:row>
<p:row>
<p:columns var="year" value="#{dtGroupView.years}" sortBy="#{player.getGoals(year)}" filterBy="#{player.getGoals(year)}" headerText="#{year}"/>
</p:row>
</p:columnGroup>

<p:column>
<h:outputText value="#{player.name}"/>
</p:column>
<p:column field="name" />

<p:columns value="#{dtGroupView.years}" var="year">
<h:outputText value="#{player.getGoals(year)}"/>
</p:columns>
<p:columnGroup headerText="Goals">
<p:columns var="year" value="#{dtGroupView.years}" sortBy="#{player.getGoals(year)}" filterBy="#{player.getGoals(year)}" headerText="#{year}">
<h:outputText value="#{player.getGoals(year)}"/>
</p:columns>
</p:columnGroup>

<f:facet name="footer">
<h:outputText value="Data between 2010-2014" styleClass="font-bold" />
<h:outputText value="Data between 2010-2014" styleClass="font-bold"/>
</f:facet>
</p:dataTable>
</h:form>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,37 +24,31 @@
NBA Teams
</f:facet>

<p:columnGroup type="header">
<p:row>
<p:column rowspan="2" headerText="Team"/>
<p:column colspan="2" headerText="Stats"/>
</p:row>
<p:row>
<p:column headerText="Wins"/>
<p:column headerText="Losses"/>
</p:row>
</p:columnGroup>

<p:subTable var="stats" value="#{team.stats}">
<f:facet name="header">
<h:outputText value="#{team.name}"/>
</f:facet>
<p:column>
<h:outputText value="#{stats.season}"/>
</p:column>
<p:column>
<h:outputText value="#{stats.win}"/>
</p:column>
<p:column>
<h:outputText value="#{stats.loss}"/>
</p:column>
<p:columnGroup type="footer">

<p:column headerText="Team" field="season" sortable="false" filterable="false"/>

<p:columnGroup headerText="Stats">
<p:column headerText="Wins" field="win" sortable="false" filterable="false"/>
<p:column headerText="Losses" field="loss" sortable="false" filterable="false"/>
</p:columnGroup>

<f:facet name="footer">
<p:row>
<p:column footerText="Totals: " class="text-right font-bold"/>
<p:column footerText="#{team.allWins}" class="font-bold"/>
<p:column footerText="#{team.allLosses}" class="font-bold"/>
<p:column class="text-right font-bold">
Totals:
</p:column>
<p:column class="font-bold">
#{team.allWins}
</p:column>
<p:column class="font-bold">
#{team.allLosses}
</p:column>
</p:row>
</p:columnGroup>
</f:facet>
</p:subTable>
</p:dataTable>
</div>
Expand Down