如何在一个Primefaces datatable中表示嵌套数据? [英] How to represent nested data in a Primefaces datatable?
问题描述
这是我的模型:
User.java
public class User {
// ...
public List< User> getFriends(){
// ...
}
}
我想建立一个这样的用户界面:
users.jsf
+ ---------- + ------------ +
| USER |朋友|
+ ---------- + ------------ +
| | ALICE |
| + ------------ +
| ADAM | BOB |
| + ------------ +
| | PITT |
+ ---------- + ------------ +
| | |
....
由于有很多用户,无法一次转储用户表。 p>
在这种情况下,datatable组件是理想的,因为它具有内置的分页支持。
这是理想的,因为它可以排序列...
不幸的是,我无法通过Primefaces的例子找到一种更改用户列中的rowspan。
如何构建此datatable?
某些其他OP具有此类似问题:
strong>
这是我想到的最终解决方案。
基于@ Kerem的答案,这里是我想出的解决方案:
为了使嵌套的datable像主datatable的自己行,我已经覆盖了CSS类 .ui-dt-c
。检查 h:head
style
标签的详细信息。
<?xml version =1.0encoding =UTF-8?>
< html
xmlns =http://www.w3c.org/1999/xhtml
xmlns:h =http://java.sun.com/jsf/html
xmlns:f =http://java.sun.com/jsf/core
xmlns:p =http://primefaces.org/ui
xmlns:fn =http://java.sun.com/jsp/jstl/functions
xmlns:ui =http://java.sun.com/jsf/facelets>
< h:head>
< title> USERS及其朋友< / title>
< style>
.ui-dt-c {
padding:0px!important;
}
< / style>
< / h:head>
< h:body>
< h:form id =form>
< p:dataTable
value =#{users.list}
var =u>
< p:columnGroup type =header>
< p:row>
< p:column headerText =USER/>
< p:column headerText =FRIENDS/>
< / p:row>
< / p:columnGroup>
< p:column>#{u.name}< / p:column>
< p:column>
< p:dataTable
value =#{u.friends}
var =f>
< p:column>#{f.name}< / p:column>
< / p:dataTable>
< / p:column>
< / p:dataTable>
< / h:form>
Here is my model :
User.java
public class User {
//...
public List<User> getFriends() {
// ...
}
}
I would like to build a table of user friends like this :
users.jsf
+----------+------------+ | USER | FRIENDS | +----------+------------+ | | ALICE | | +------------+ | ADAM | BOB | | +------------+ | | PITT | +----------+------------+ | | | ....
Since there are many users, it's not possible to dump the user table in one go.
The datatable component is ideal in this case because it has built-in pagination support. It is ideal too because it's possible to sort columns...
Unfortunately, I wasn't able to find through the Primefaces examples a way for changing the rowspan in user columns.
How can I build this datatable ?
Some other OP having this similar issue:
- Primefaces/JSF Nested Data Table
- How to do a dataTable containing a subtable with Primefaces in the same row? What's doing with mine?
- Primefaces dataTable with rowspan
- ... Add yours?
EDIT
Here is the final solution I came up.
Based on @Kerem's answer, here is the solution I came up with:
In order to make the nested datable like own rows of main datatable, I have overriden the CSS class .ui-dt-c
. Check in h:head
the style
tag for details.
<?xml version="1.0" encoding="UTF-8"?>
<html
xmlns="http://www.w3c.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:fn="http://java.sun.com/jsp/jstl/functions"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
<title>USERS and their friends</title>
<style>
.ui-dt-c {
padding: 0px !important;
}
</style>
</h:head>
<h:body>
<h:form id="form">
<p:dataTable
value="#{users.list}"
var="u">
<p:columnGroup type="header">
<p:row>
<p:column headerText="USER" />
<p:column headerText="FRIENDS" />
</p:row>
</p:columnGroup>
<p:column>#{u.name}</p:column>
<p:column>
<p:dataTable
value="#{u.friends}"
var="f">
<p:column>#{f.name}</p:column>
</p:dataTable>
</p:column>
</p:dataTable>
</h:form>
这篇关于如何在一个Primefaces datatable中表示嵌套数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!