How should I display list of lists with parent and child combined
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
2
down vote
favorite
I am having a data structure similar to this:
Class A
public String Name;
public String status;
public List<B>;
In the Visualforce page, I need to display both A and B's information in one table. Like below:
Please note that A1 and B1 will be in the same line of the table.
I am not quite sure how should I achieve this in Visualforce by using apex:repeat. I am thinking of using another wrapper class to hold both A and B's information and if B is not the first child, the related A information can be blank. However, this still sounds a bit strange to me.
Any suggestions?
visualforce
add a comment |Â
up vote
2
down vote
favorite
I am having a data structure similar to this:
Class A
public String Name;
public String status;
public List<B>;
In the Visualforce page, I need to display both A and B's information in one table. Like below:
Please note that A1 and B1 will be in the same line of the table.
I am not quite sure how should I achieve this in Visualforce by using apex:repeat. I am thinking of using another wrapper class to hold both A and B's information and if B is not the first child, the related A information can be blank. However, this still sounds a bit strange to me.
Any suggestions?
visualforce
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I am having a data structure similar to this:
Class A
public String Name;
public String status;
public List<B>;
In the Visualforce page, I need to display both A and B's information in one table. Like below:
Please note that A1 and B1 will be in the same line of the table.
I am not quite sure how should I achieve this in Visualforce by using apex:repeat. I am thinking of using another wrapper class to hold both A and B's information and if B is not the first child, the related A information can be blank. However, this still sounds a bit strange to me.
Any suggestions?
visualforce
I am having a data structure similar to this:
Class A
public String Name;
public String status;
public List<B>;
In the Visualforce page, I need to display both A and B's information in one table. Like below:
Please note that A1 and B1 will be in the same line of the table.
I am not quite sure how should I achieve this in Visualforce by using apex:repeat. I am thinking of using another wrapper class to hold both A and B's information and if B is not the first child, the related A information can be blank. However, this still sounds a bit strange to me.
Any suggestions?
visualforce
visualforce
asked 1 hour ago
Lance Shi
7,22722569
7,22722569
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
1
down vote
You just have a List<Child__c>
. Within each row, you can then reference fields on Parent__c
or Child__c
.
<apex:pageBlockTable value="!children" var="child">
<apex:column value="!child.Parent__r.Name" />
<apex:column value="!child.Name" />
</apex:pageBlockTable>
Make sure in your query you ORDER BY Parent__c
.
If you want to only display parent details for the first row in a grouping, you could use a wrapper like below:
public class Wrapper
public Parent__c parent;
public Child__c child;`
Then in your controller, you can do some algorithm along the following lines:
public List<Wrapper> wrappers get; private set;
public MyController()
for (Parent__c parent : [/*query*/])
Boolean isFirstChild = true;
for (Child__c child : parent.Children__r)
Wrapper wrapper = new Wrapper();
wrapper.child = child;
if (isFirstChild)
wrapper.parent = parent;
isFirstChild = false;
else
wrapper.parent = new Parent__c();
// you need an empty record to avoid NullPointerException
Thank you for your answer, Adrian. However, if you look at the table, both B1, B2, B3 should have the parent A1. However, only the line with B1 should show related parent's information.
â Lance Shi
56 mins ago
add a comment |Â
up vote
1
down vote
You can iterate List<Child__c>
and your list should be ordered by parent__c
. In visualforce you can handle above thing as :
<apex:varaible var="parentId" value="" />
<apex:pageBlockTable value="!children" var="child">
<apex:column value="!IF(children.Parent__c != parentId , child.Parent__r.Name, ''" />
<apex:column value="!child.Name" />
<apex:column value="!child.Description__c" />
<apex:variable value="!child.Parent__c" var="parentId"/>
</apex:pageBlockTable>
does above solution worked for you?
â Pragati Jain
4 mins ago
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
You just have a List<Child__c>
. Within each row, you can then reference fields on Parent__c
or Child__c
.
<apex:pageBlockTable value="!children" var="child">
<apex:column value="!child.Parent__r.Name" />
<apex:column value="!child.Name" />
</apex:pageBlockTable>
Make sure in your query you ORDER BY Parent__c
.
If you want to only display parent details for the first row in a grouping, you could use a wrapper like below:
public class Wrapper
public Parent__c parent;
public Child__c child;`
Then in your controller, you can do some algorithm along the following lines:
public List<Wrapper> wrappers get; private set;
public MyController()
for (Parent__c parent : [/*query*/])
Boolean isFirstChild = true;
for (Child__c child : parent.Children__r)
Wrapper wrapper = new Wrapper();
wrapper.child = child;
if (isFirstChild)
wrapper.parent = parent;
isFirstChild = false;
else
wrapper.parent = new Parent__c();
// you need an empty record to avoid NullPointerException
Thank you for your answer, Adrian. However, if you look at the table, both B1, B2, B3 should have the parent A1. However, only the line with B1 should show related parent's information.
â Lance Shi
56 mins ago
add a comment |Â
up vote
1
down vote
You just have a List<Child__c>
. Within each row, you can then reference fields on Parent__c
or Child__c
.
<apex:pageBlockTable value="!children" var="child">
<apex:column value="!child.Parent__r.Name" />
<apex:column value="!child.Name" />
</apex:pageBlockTable>
Make sure in your query you ORDER BY Parent__c
.
If you want to only display parent details for the first row in a grouping, you could use a wrapper like below:
public class Wrapper
public Parent__c parent;
public Child__c child;`
Then in your controller, you can do some algorithm along the following lines:
public List<Wrapper> wrappers get; private set;
public MyController()
for (Parent__c parent : [/*query*/])
Boolean isFirstChild = true;
for (Child__c child : parent.Children__r)
Wrapper wrapper = new Wrapper();
wrapper.child = child;
if (isFirstChild)
wrapper.parent = parent;
isFirstChild = false;
else
wrapper.parent = new Parent__c();
// you need an empty record to avoid NullPointerException
Thank you for your answer, Adrian. However, if you look at the table, both B1, B2, B3 should have the parent A1. However, only the line with B1 should show related parent's information.
â Lance Shi
56 mins ago
add a comment |Â
up vote
1
down vote
up vote
1
down vote
You just have a List<Child__c>
. Within each row, you can then reference fields on Parent__c
or Child__c
.
<apex:pageBlockTable value="!children" var="child">
<apex:column value="!child.Parent__r.Name" />
<apex:column value="!child.Name" />
</apex:pageBlockTable>
Make sure in your query you ORDER BY Parent__c
.
If you want to only display parent details for the first row in a grouping, you could use a wrapper like below:
public class Wrapper
public Parent__c parent;
public Child__c child;`
Then in your controller, you can do some algorithm along the following lines:
public List<Wrapper> wrappers get; private set;
public MyController()
for (Parent__c parent : [/*query*/])
Boolean isFirstChild = true;
for (Child__c child : parent.Children__r)
Wrapper wrapper = new Wrapper();
wrapper.child = child;
if (isFirstChild)
wrapper.parent = parent;
isFirstChild = false;
else
wrapper.parent = new Parent__c();
// you need an empty record to avoid NullPointerException
You just have a List<Child__c>
. Within each row, you can then reference fields on Parent__c
or Child__c
.
<apex:pageBlockTable value="!children" var="child">
<apex:column value="!child.Parent__r.Name" />
<apex:column value="!child.Name" />
</apex:pageBlockTable>
Make sure in your query you ORDER BY Parent__c
.
If you want to only display parent details for the first row in a grouping, you could use a wrapper like below:
public class Wrapper
public Parent__c parent;
public Child__c child;`
Then in your controller, you can do some algorithm along the following lines:
public List<Wrapper> wrappers get; private set;
public MyController()
for (Parent__c parent : [/*query*/])
Boolean isFirstChild = true;
for (Child__c child : parent.Children__r)
Wrapper wrapper = new Wrapper();
wrapper.child = child;
if (isFirstChild)
wrapper.parent = parent;
isFirstChild = false;
else
wrapper.parent = new Parent__c();
// you need an empty record to avoid NullPointerException
edited 42 mins ago
answered 1 hour ago
Adrian Larsonâ¦
101k19108228
101k19108228
Thank you for your answer, Adrian. However, if you look at the table, both B1, B2, B3 should have the parent A1. However, only the line with B1 should show related parent's information.
â Lance Shi
56 mins ago
add a comment |Â
Thank you for your answer, Adrian. However, if you look at the table, both B1, B2, B3 should have the parent A1. However, only the line with B1 should show related parent's information.
â Lance Shi
56 mins ago
Thank you for your answer, Adrian. However, if you look at the table, both B1, B2, B3 should have the parent A1. However, only the line with B1 should show related parent's information.
â Lance Shi
56 mins ago
Thank you for your answer, Adrian. However, if you look at the table, both B1, B2, B3 should have the parent A1. However, only the line with B1 should show related parent's information.
â Lance Shi
56 mins ago
add a comment |Â
up vote
1
down vote
You can iterate List<Child__c>
and your list should be ordered by parent__c
. In visualforce you can handle above thing as :
<apex:varaible var="parentId" value="" />
<apex:pageBlockTable value="!children" var="child">
<apex:column value="!IF(children.Parent__c != parentId , child.Parent__r.Name, ''" />
<apex:column value="!child.Name" />
<apex:column value="!child.Description__c" />
<apex:variable value="!child.Parent__c" var="parentId"/>
</apex:pageBlockTable>
does above solution worked for you?
â Pragati Jain
4 mins ago
add a comment |Â
up vote
1
down vote
You can iterate List<Child__c>
and your list should be ordered by parent__c
. In visualforce you can handle above thing as :
<apex:varaible var="parentId" value="" />
<apex:pageBlockTable value="!children" var="child">
<apex:column value="!IF(children.Parent__c != parentId , child.Parent__r.Name, ''" />
<apex:column value="!child.Name" />
<apex:column value="!child.Description__c" />
<apex:variable value="!child.Parent__c" var="parentId"/>
</apex:pageBlockTable>
does above solution worked for you?
â Pragati Jain
4 mins ago
add a comment |Â
up vote
1
down vote
up vote
1
down vote
You can iterate List<Child__c>
and your list should be ordered by parent__c
. In visualforce you can handle above thing as :
<apex:varaible var="parentId" value="" />
<apex:pageBlockTable value="!children" var="child">
<apex:column value="!IF(children.Parent__c != parentId , child.Parent__r.Name, ''" />
<apex:column value="!child.Name" />
<apex:column value="!child.Description__c" />
<apex:variable value="!child.Parent__c" var="parentId"/>
</apex:pageBlockTable>
You can iterate List<Child__c>
and your list should be ordered by parent__c
. In visualforce you can handle above thing as :
<apex:varaible var="parentId" value="" />
<apex:pageBlockTable value="!children" var="child">
<apex:column value="!IF(children.Parent__c != parentId , child.Parent__r.Name, ''" />
<apex:column value="!child.Name" />
<apex:column value="!child.Description__c" />
<apex:variable value="!child.Parent__c" var="parentId"/>
</apex:pageBlockTable>
edited 22 mins ago
answered 32 mins ago
Pragati Jain
64048
64048
does above solution worked for you?
â Pragati Jain
4 mins ago
add a comment |Â
does above solution worked for you?
â Pragati Jain
4 mins ago
does above solution worked for you?
â Pragati Jain
4 mins ago
does above solution worked for you?
â Pragati Jain
4 mins ago
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f235940%2fhow-should-i-display-list-of-lists-with-parent-and-child-combined%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password