How should I display list of lists with parent and child combined

The name of the pictureThe name of the pictureThe name of the pictureClash 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:
enter image description here



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?










share|improve this question



























    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:
    enter image description here



    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?










    share|improve this question























      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:
      enter image description here



      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?










      share|improve this question













      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:
      enter image description here



      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 1 hour ago









      Lance Shi

      7,22722569




      7,22722569




















          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









          share|improve this answer






















          • 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
            57 mins ago

















          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>





          share|improve this answer






















          • does above solution worked for you?
            – Pragati Jain
            5 mins ago










          Your Answer







          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "459"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













           

          draft saved


          draft discarded


















          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






























          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









          share|improve this answer






















          • 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
            57 mins ago














          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









          share|improve this answer






















          • 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
            57 mins ago












          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









          share|improve this answer














          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










          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 43 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
            57 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
            57 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
          57 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
          57 mins ago












          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>





          share|improve this answer






















          • does above solution worked for you?
            – Pragati Jain
            5 mins ago














          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>





          share|improve this answer






















          • does above solution worked for you?
            – Pragati Jain
            5 mins ago












          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>





          share|improve this answer














          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>






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 23 mins ago

























          answered 33 mins ago









          Pragati Jain

          64048




          64048











          • does above solution worked for you?
            – Pragati Jain
            5 mins ago
















          • does above solution worked for you?
            – Pragati Jain
            5 mins ago















          does above solution worked for you?
          – Pragati Jain
          5 mins ago




          does above solution worked for you?
          – Pragati Jain
          5 mins ago

















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          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













































































          Comments

          Popular posts from this blog

          Long meetings (6-7 hours a day): Being “babysat” by supervisor

          Is the Concept of Multiple Fantasy Races Scientifically Flawed? [closed]

          Confectionery