You need to sign in to do that
Don't have an account?
Chelsea Lukowski
Visualforce display fields from a child record on parent record table
I have a visualforce page used to search for products and calculate a price, when the list populates I want it to display fields from a related list called Inventory. Sometimes there are more than one inventory record to the product and sometimes there are no inventory records to products. If there are no records, I want it to just display the Product infromation. If there are more than one child record, I would like it to diplay both child records on seperate rows.
Parent Object: Product2
Child Object: Inventory__c
Here is my visualforce page:
Here is my controller:
This is what it looks like now:
I would like the highlighted line to display 2 lines. One with 72 and 62 in the last two columns and the second line with 50 and 47 in the las two columns.
Parent Object: Product2
Child Object: Inventory__c
Here is my visualforce page:
<apex:page Controller="ProductPricingInventoryMobileController" standardStylesheets="false" readOnly="true" docType="html-5.0" > <apex:form > <apex:tabPanel switchType="client" selectedTab="sch" id="dataTabPanel" tabClass="myActiveTab" inactiveTabClass="myInactiveTab"> <apex:tab label="Inventory" name="Inventory Search" id="sch" > <br/> <apex:outputPanel id="idToRerenderInv"> <apex:outputLabel for="input" value="Search:" styleClass="fieldLabel"></apex:outputLabel> <apex:input id="input" value="{!searchstring}" label="Input"/> <br/> <br/> <apex:commandButton value="Go" action="{!search}" rerender="idToRerenderInv" styleClass="buttonStyle"/> <apex:commandButton value="Clear" action="{!clear}" rerender="idToRerenderInv" styleClass="buttonStyle"/> <br/> <br/> <h1> Search Results </h1> <apex:outputPanel id="invtext" style="width:100%" rendered="{!AND(invList.size=0,searchstring != '')}" styleclass="noDisplay"> No records to display </apex:outputPanel> <br/> <br/> <c:ProductPricingInventoryMobileComponent /> <table> <tr> <th>Product Code</th> <th>Available</th> <th>List Price</th> <th>Warehouse</th> <th>Weight Per U/M</th> </tr> <apex:repeat value="{!invList}" var="i"> <tr> <td style="page-break-inside: avoid;border:1px solid black;padding: 7px;word-wrap: break-word;text-align:center;">{!i.Product__r.ProductCode}</td> <td style="page-break-inside: avoid;border:1px solid black;padding: 7px;word-wrap: break-word;text-align:center;">{!i.Available__c}</td> <td style="page-break-inside: avoid;border:1px solid black;padding: 7px;word-wrap: break-word;text-align:center;">${!i.Product__r.Standard_Price__c}</td> <td style="page-break-inside: avoid;border:1px solid black;padding: 7px;word-wrap: break-word;text-align:center;">{!i.Warehouse__c}</td> <td style="page-break-inside: avoid;border:1px solid black;padding: 7px;word-wrap: break-word;text-align:center;">{!i.Weight_Per_U_M__c}</td> </tr> </apex:repeat> </table> </apex:outputPanel> </apex:tab> <apex:tab label="Pricing" name="Pricing Calculator" id="sch2"> <br/> <apex:outputPanel id="idToRerender"> <apex:outputLabel for="criteria" value="Product Code:" styleClass="fieldLabel"></apex:outputLabel> <apex:input id="criteria" value="{!productsearchstring}" label="Input" styleClass="inputfields" /> <br/> <br/> <apex:outputLabel for="discountlist" value="On-Factor:" styleClass="fieldLabel"></apex:outputLabel> <apex:selectList id="discountlist" value="{!discountsearchstring}" size="1" label="On-Factor:"> <apex:SelectOption itemValue="0.0" itemLabel=""/> <apex:SelectOption itemValue=".35" itemLabel=".35"/> <apex:SelectOption itemValue=".419" itemLabel=".419"/> <apex:SelectOption itemValue=".432" itemLabel=".432"/> <apex:SelectOption itemValue=".437" itemLabel=".437"/> <apex:SelectOption itemValue=".45" itemLabel=".45"/> <apex:SelectOption itemValue=".478" itemLabel=".478"/> <apex:SelectOption itemValue=".50" itemLabel=".50"/> <apex:SelectOption itemValue=".51" itemLabel=".51"/> <apex:SelectOption itemValue=".52" itemLabel=".52"/> <apex:actionSupport event="onchange" action="{!query}" rerender="idToRerender"/> </apex:selectList> <br/> <br/> <apex:commandButton value="Go" action="{!query}" rerender="idToRerender" styleClass="buttonStyle"/> <apex:commandButton value="Clear" action="{!clearProducts}" rerender="idToRerender" styleClass="buttonStyle"/> <br/> <br/> <h1> Search Results </h1> <apex:outputPanel id="opformofauth" style="width:100%" rendered="{!AND(ProdList.size=0,productsearchstring!='')}" styleclass="noDisplay"> No records to display </apex:outputPanel> <br/> <br/> <table> <tr> <th>Product Code</th> <th>Name</th> <th>Price</th> <th>Available</th> <th>Warehouse</th> </tr> <apex:repeat value="{!prodList}" var="p"> <tr> <td style="page-break-inside: avoid;border:1px solid black;padding: 7px;word-wrap: break-word;text-align:center;">{!p.ProductCode}</td> <td style="page-break-inside: avoid;border:1px solid black;padding: 7px;word-wrap: break-word;text-align:center;">{!p.Name}</td> <td style="page-break-inside: avoid;border:1px solid black;padding: 7px;word-wrap: break-word;text-align:center;"> ${!ROUND(IF(discountsearchstring != 0 , discountsearchstring * p.Standard_Price__c, p.Standard_Price__c ),2)} </td> <apex:repeat value="{!p.Inventory__r}" var="inv"> <td style="page-break-inside: avoid;border:1px solid black;padding: 7px;word-wrap: break-word;text-align:center;">{!inv.Available__c}</td> <td style="page-break-inside: avoid;border:1px solid black;padding: 7px;word-wrap: break-word;text-align:center;">{!inv.Warehouse__c}</td> </apex:repeat> </tr> </apex:repeat> </table> </apex:outputPanel> </apex:tab> </apex:tabPanel> </apex:form> </apex:page>
Here is my controller:
public class ProductPricingInventoryMobileController { public string searchstring { get {return searchstring;} set {searchstring = value;} } public list<Inventory__c> invList {get;set;} public string productsearchstring { get {return productsearchstring;} set {productsearchstring = value;} } public double discountsearchstring {get;set;} public list<Product2> prodList {get;set;} public PageReference search(){ String searchResults = '%' + searchstring + '%'; system.debug('search Results - ' + searchstring); if(searchstring != Null){ invList = [select Lookup_Key__c,Product__r.ProductCode,Product__r.Name,Weight_Per_U_M__c,Available__c,Warehouse__c,Warehouse_City__c,Product__r.Standard_Price__c,id from Inventory__c where Lookup_Key__c LIKE: searchResults ORDER BY Product__r.ProductCode ASC]; }else{ invList = [select Lookup_Key__c,Product__r.ProductCode,Product__r.Name,Weight_Per_U_M__c,Available__c,Warehouse__c,Warehouse_City__c,Product__r.Standard_Price__c,id from Inventory__c ORDER BY Product__r.ProductCode ASC]; } system.debug('invList = ' + invList.size()); system.debug('invList = ' + invList); return null; } public PageReference query() { String productsearchResults = '%' + productsearchstring + '%'; system.debug('Search String - ' + productsearchstring ); if(productsearchstring == Null || productsearchstring == ''){ prodList = [select Name,ProductCode,Search_String__c,(Select Id,Product__c,Warehouse__c,Available__c FROM Inventory__r ),Include_in_Price_Book__c,Inventory_Count__c, Standard_Price__c from Product2 where (Material_Type__c !='Yes' OR Obsolete__c != 'Yes') AND Standard_Price__c < 99999.99 AND Include_in_Price_Book__c = true ORDER BY ProductCode ASC]; }else{ prodList = [select Name, ProductCode,Search_String__c,Include_in_Price_Book__c,(Select Id,Warehouse__c,Available__c FROM Inventory__r),Inventory_Count__c, Standard_Price__c from Product2 where (Material_Type__c !='Yes' OR Obsolete__c != 'Yes') AND Standard_Price__c < 99999.99 AND ProductCode LIKE: productsearchResults ORDER BY ProductCode ASC]; } system.debug('prodList = ' + prodList.size()); system.debug('prodList = ' + prodList); return null; } public void clearProducts(){ system.debug('prodList - ' + prodList.size()); if(prodList.size() > 0){ productsearchstring = ''; discountsearchstring = 0.0; prodList.clear(); }else { productsearchstring = ''; discountsearchstring = 0.0; } } public void clear(){ searchstring = ''; invList.clear(); } }
This is what it looks like now:
I would like the highlighted line to display 2 lines. One with 72 and 62 in the last two columns and the second line with 50 and 47 in the las two columns.