function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Swamy P R NSwamy P R N 

Showing records in pageblock table in an proper order by a unique names

Hello Everyone,

Iam showing records in an pageblock table by using wrapper class.
User-added image
In the above image, showing records in an table. left hand side products are parent object records and right side records are child object product feature records. For a single parent record i have to show all the associated childs in rightside column but currently in table, product is repeatly coming with every product feature. 
Actually it has to show one "Diesel Generator" in right side and "Black Colour","Brown Colour" features has to show in right side, mainly it has to show in one block. i.e, resultly it has to show like in the below image.User-added image
vf code:
<apex:pageBlockTable value="{!selectedPrdctsWithFeatures}" var="spf">
             <apex:column value="{!spf.selectedProdctname}" headerValue="Product"/>
             <apex:column headerValue="Product Features">
                     <table border="1">
                          <tr> <th><b>Select</b></th>
                                   <th><b>Colour</b></th>
                                   <th><b>Engine Capacity</b></th>
                          </tr>
                          <tr>                                
                               <td width="30%">
                                    <apex:inputCheckbox value="{!spf.selectfeature}"/>
                                </td>
                                <td align="center">
                                     <apex:outputText value="{!spf.pftr.Product_Colour__c}"/>
                                </td>
                                <td align="center">
                                    <apex:outputText value="{!spf.pftr.Engine_Capacity__c}"/>
                                </td>
                          </tr>
                    </table>
             </apex:column>
   </apex:pageBlockTable>
Class::
  for(Product_Feature__c pf: [select id,Product_Colour__c,Engine_Capacity__c,Product__r.Name,Product__r.Product_Code__c,Product__c                                                                    from Product_Feature__c where Product__c IN:cstmprdctMap.keyset()]){
                                                                                    selectedPrdctsWithFeatures.add(new CPQsubWrapper(pf.Product__r.Name,pf.Product__r.Product_Code__c,false,pf,null,null,null,null,null,null));   
   }
Please update me where can i change the logic to show my records as in second image.
 
Pankaj_GanwaniPankaj_Ganwani
Hi,

Can you please use following code and try to check if this is giving you the expected output. Please correct the mistakes related to typo or syntax if any:
 
Controller: 

public class ChildWrapper
{
     public Boolean selectfeature	{get;set;}
	 public String productCode		{get;set;}
	 public String enginecapacity	{get;set;}
	 public ChildWrapper(Boolean selectfeature, String productCode, String enginecapacity)
	 {
	      this.selectfeature = selectfeature;
		  this.productCode = productCode;
		  this.enginecapacity = enginecapacity;
	 }
}
public class MainWrapper
{
	public String productName	{get;set;}
	public List<ChildWrapper> lstWrapper {get;set;}
	public MainWrapper(string productName, List<ChildWrapper> lstWrapper)
	{
	    this.productName = productName;
		this.lstWrapper = lstWrapper;
	}
}


Map<String,List<ChildWrapper>> mapProductNameToChildWrapper = new Map<String,List<ChildWrapper>>();
List<MainWrapper> lstMainWrapper = new List<MainWrapper>();
for(Product_Feature__c pf: [select id,Product_Colour__c,Engine_Capacity__c,Product__r.Name,Product__r.Product_Code__c,Product__c from Product_Feature__c where Product__c IN:cstmprdctMap.keyset()])
{
    if(!mapProductNameToChildWrapper.containskey(pf.Product__r.Name))
		mapProductNameToChildWrapper.put(pf.Product__r.Name, new List<ChildWrapper>{new ChildWrapper(false,pf.Product_Code__c,pf.Engine_Capacity__c)});
	else
		mapProductNameToChildWrapper.get(pf.Product__r.Name).add(new ChildWrapper(false,pf.Product_Code__c,pf.Engine_Capacity__c));
}

for(String str : mapProductNameToChildWrapper.keyset())
{
   lstMainWrapper.add(new MainWrapper(str, mapProductNameToChildWrapper.get(str)));
}

VF page:

<apex:pageBlockTable value="{!lstMainWrapper}" var="spf">
             <apex:column value="{!spf.productName}" headerValue="Product"/>
             <apex:column headerValue="Product Features">
                     <table border="1">
                          <tr> <th><b>Select</b></th>
                                   <th><b>Colour</b></th>
                                   <th><b>Engine Capacity</b></th>
                          </tr>
						  <apex:repeat value="{!spf.lstWrapper}" var="objChild">
							  <tr>                                
								   <td width="30%">
										<apex:inputCheckbox value="{!objChild.selectfeature}"/>
									</td>
									<td align="center">
										 <apex:outputText value="{!objChild.Product_Colour__c}"/>
									</td>
									<td align="center">
										<apex:outputText value="{!objChild.Engine_Capacity__c}"/>
									</td>
							  </tr>
						  </apex:repeat>
                    </table>
             </apex:column>
   </apex:pageBlockTable>

 
Swamy P R NSwamy P R N
Hi Pankaj,
 
Thank you so much for your response but actually i'm using one wrapper class instead of two classes which you sent. I have only one wrapper class i.e,
 public class CPQsubWrapper{
            public string selectedProdctname{get;set;}
            public string prdctCode{get;set;}
            public Boolean selectfeature{get;set;}
            public Product_Feature__c pftr{get;set;}
            public Integer qnty{get;set;}
            public string couponCode{get;set;}
            public Decimal discnt{get;set;}
            public Decimal actualPrice{get;set;}
            public Decimal listPrice{get;set;}
            public Integer totalAmount{get;set;}
            public CPQsubWrapper(string sp, string sprdid, Boolean sfr, Product_Feature__c pr, Integer q, string cc, Decimal ds, Decimal ap, Decimal lp, Integer ta){
                this.selectedProdctname=sp;
                this.prdctCode=sprdid;
                this.selectfeature=sfr;
                this.pftr=pr;
                this.qnty=q;
                this.couponCode=cc;
                this.discnt=ds;
                this.actualPrice=ap;
                this.listPrice=lp;
                this.totalAmount=ta;
            }
    }        

So if you don't mind can you check with this, how can i with this class???

Thanks in advance :)