You need to sign in to do that
Don't have an account?
❤Code
Display fields even if values are not there in pageblocktable
I have a pageblocktable like below
The column from Product to Treatment Unit Price are the fields from Product2. Column from Service to Width are the fields from Object WorkOrderItem__c.
WorkOrderItem__c is a related list to Product2.
I want if there are no WorkOrderItem__c records for a Product2, fields should appear. Not it is showing notthing on vf page if there are no records. Below is the class and vf page -
Regards
The column from Product to Treatment Unit Price are the fields from Product2. Column from Service to Width are the fields from Object WorkOrderItem__c.
WorkOrderItem__c is a related list to Product2.
I want if there are no WorkOrderItem__c records for a Product2, fields should appear. Not it is showing notthing on vf page if there are no records. Below is the class and vf page -
public with sharing class wrapper_test_controller { public list<wrapperclass> wrapperelement_for_account{get;set;} public list<wrapperclass> wrapperelement_for_contact{get;set;} public string selectedproductfamily {get;set;} public list<product2> queryResult{get;set;} public list<Work_Order_Item__c> queryResult1{get;set;} public List<SelectOption> getproductfamily(){ List<SelectOption> options = new List<SelectOption>(); options.add(new SelectOption('None', 'None')); options.add(new SelectOption('Bedding', 'Bedding')); options.add(new SelectOption('Flooring', 'Flooring')); options.add(new SelectOption('Seating', 'Seating')); options.add(new SelectOption('Wall Treatments', 'Wall Treatments')); options.add(new SelectOption('Other', 'Other')); return options; } public PageReference query() { system.debug('@@@'+selectedproductfamily); // String qryString = 'select Product__r.IsActive ,Product__r.Measurement_Type__c,Product__r.Treatment_Unit_Price__c,Product__r.Cleaning_Unit_Price__c,Product__c,Product__r.Name,Product__r.Family,id,name,Service__c,Quantity__c,Length__c,Width__c from Work_Order_Item__c WHERE ' + // '(Product__r.Family like \'%' + selectedproductfamily + '%\')'; String qryString = 'SELECT Id,name,family,Measurement_Type__c,Cleaning_Unit_Price__c,Treatment_Unit_Price__c,(select Service__c,Quantity__c,Length__c,Width__c from work_order_items__R) FROM product2 WHERE ' + '(Family like \'%' + selectedproductfamily + '%\')'; queryResult = Database.query(qryString); return null; } //list<Product2> object1 = [select id,name,Family,Measurement_Type__c,Treatment_Unit_Price__c,Cleaning_Unit_Price__c from Product2 limit 10]; //list<Work_Order_Item__c> object2 = [select Product__r.Measurement_Type__c,Product__r.Treatment_Unit_Price__c,Product__r.Cleaning_Unit_Price__c,Product__c,Product__r.Name,Product__r.Family,id,name,Service__c,Quantity__c,Length__c,Width__c from Work_Order_Item__c limit 10]; public wrapper_test_controller (ApexPages.StandardController controller) { } public list<wrapperclass> getPieData() { List<wrapperclass> data = new List<wrapperclass>(); AggregateResult[] groupedResults = [SELECT Product__r.Family f,count(Id) c FROM Work_Order_Item__c WHERE Product__r.Family != null GROUP BY Product__r.Family]; for (AggregateResult ar : groupedResults) { data.add(new wrapperclass(String.ValueOf(ar.get('f')),Integer.ValueOf(ar.get('c')))); } return data; } public class wrapperclass{ public String name { get; set; } public Integer data { get; set; } public Product2 account {get;set;} public Work_Order_Item__c service {get;set;} public wrapperclass(String Name,Integer data) { this.name = Name; this.data = data; } public wrapperclass (Work_Order_Item__c record){ this.service = record; } } }
<apex:page standardController="Work_Order__c" extensions="wrapper_test_controller"> <apex:form > <apex:pageblock id="pb"> <apex:pageBlockButtons > <apex:commandButton action="{!save}" value="Save" /> <apex:commandButton action="{!Cancel}" value="Cancel" /> </apex:pageBlockButtons > <apex:pageblockSection title="Work Order Details"> <apex:outputfield label="Account" value="{!Work_Order__c.Account__c}" id="a"/> <apex:inputField label="Status" value="{!Work_Order__c.Status__c}" required="true"/> <apex:inputField label="Service Date" value="{!Work_Order__c.Service_Date__c}" required="true"/> </apex:pageblockSection> <apex:pageblockSection title="Summary"> <apex:chart height="350" width="450" data="{!pieData}"> <apex:pieSeries dataField="data" labelField="name"/> <apex:legend position="bottom"/> </apex:chart> </apex:pageblockSection> <apex:pageblocksection title="Products" > <apex:outputPanel title="Family"> <apex:outputLabel value="Family:"> <apex:actionRegion > <apex:selectList value="{!selectedproductfamily}" size="1" label="Family" rendered="true" > <apex:actionSupport action="{!query}" reRender="pb1" id="fam" event="onchange"/> <apex:selectOptions value="{!productfamily}" /> </apex:selectList> </apex:actionRegion> </apex:outputLabel> </apex:outputPanel> </apex:pageblocksection> <!-- </apex:pageBlock> --> <!-- <apex:pageBlock id="pb1" mode="edit"> --> <apex:pageblocktable value="{!queryResult}" var="acc" id="pb1"> <apex:column > <apex:facet name="header">Name</apex:facet> <apex:outputfield value="{!acc.Name}" /> </apex:column> <apex:column headervalue="Family"> <apex:outputfield value="{!acc.Family}" /> </apex:column> <apex:column headervalue="Measurement Type"> <apex:outputfield value="{!acc.Measurement_Type__c}" /> </apex:column> <apex:column headervalue="Treatment Price"> <apex:outputfield value="{!acc.Treatment_Unit_Price__c}" /> </apex:column> <apex:column headervalue="Cleaning Unit Price"> <apex:outputfield value="{!acc.Cleaning_Unit_Price__c}" /> </apex:column> <apex:column headerValue="Service"> <apex:repeat value="{!acc.work_order_items__R}" var="b"> <apex:inputfield value="{!b.Service__c}"/> </apex:repeat> </apex:column> <apex:column headerValue="Quantity"> <apex:repeat value="{!acc.work_order_items__R}" var="b"> <apex:inputfield value="{!b.Quantity__c}"/> </apex:repeat> </apex:column> <apex:column headerValue="Length"> <apex:repeat value="{!acc.work_order_items__R}" var="b"> <apex:inputfield value="{!b.Length__c}"/> </apex:repeat> </apex:column> <apex:column headerValue="Width"> <apex:repeat value="{!acc.work_order_items__R}" var="b"> <apex:inputfield value="{!b.Width__c}"/> </apex:repeat> </apex:column> </apex:pageblocktable> </apex:pageblock> </apex:form> </apex:page>
Regards