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

conditional datatables

I want to be able to display a datatable for one object based on some criteria, and if the criteria is false, it will display a different datatable showing data from a different object. I have tried doing this with two separate datatables with complementary rendered attributes, but they just always came up blank. What would be the way to do this?

Chris ZhuangChris Zhuang

you should get that done easily with VF, Can you post your code? I am take a look.


Maybe you can see 


This is the relevant part of my attempt:


<apex:panelGrid width="100%" columns="1" cellpadding="2" cellspacing="0" style="border-bottom:2px solid #000;Font-style:Italic;font-size:14pt;" border="0">
           <apex:outputText >Product Serviced</apex:outputText>
    <apex:dataTable rendered="{!if(SVMXC__Service_Order__c.SVMXC__Is_PM_Work_Order__c == true && SVMXC__Service_Order__c.SVMXC__Service_Contract__r.PM_Rate_Total__c > 0,true,false)}"
                    columns="2" columnsWidth="70%,30%" width="100%" value="{!pmrList}" var="pmr">
                <apex:column >
                        <apex:facet name="header">Equipment Types</apex:facet>
                        <apex:outputText value="{!pmr.Equipment_Type__c}"/>

                <apex:column >
                        <apex:facet name="header">Quantity</apex:facet>
                        <apex:outputText value="{!pmr.Quantity__c}"/>
    <apex:dataTable rendered="{!if(SVMXC__Service_Order__c.SVMXC__Is_PM_Work_Order__c == false || SVMXC__Service_Order__c.SVMXC__Service_Contract__r.PM_Rate_Total__c == 0,true,false)}"
                    columns="2" columnsWidth="70%,30%" width="100%" value="{!SVMXC__Service_Order__c.SVMXC__Service_Order_Line__r}" var="wod">
                <apex:column >
                        <apex:facet name="header">Product Serviced</apex:facet>
                        <apex:outputText rendered="{!if(wod.Record_Type_Name__c=='Products_Serviced',true,false)}" value="{!wod.SVMXC__Serial_Number__r.Name}"/>

                <apex:column >
                        <apex:facet name="header">Description</apex:facet>
                        <apex:outputText rendered="{!if(wod.Record_Type_Name__c=='Products_Serviced',true,false)}" value="{!wod.SVMXC__Work_Description__c}"/>

 I want the Product Serviced heading to show up for both of them. {!pmrList} refers to a list in a controller extension - I'll produce that code here in case that's relevant:


public with sharing class WOPMRates {

public SVMXC__Service_Order__c wo { get; set; }
public List<PM_Rates__c> pmrList { get; set; }

public WOPMRates(ApexPages.StandardController stc) {

wo = [SELECT Id, SVMXC__Service_Contract__c
      FROM SVMXC__Service_Order__c
      WHERE Id = :stc.getId()];
this.pmrList = [SELECT Id, Service_Maintenance_Contract__c, Equipment_Type__c, Quantity__c
                FROM PM_Rates__c
                WHERE Service_Maintenance_Contract__c = :wo.SVMXC__Service_Contract__c];


 The pmrList pulls through fine when I don't have the rendered attribute. But with it, neither of them show up. I know I'm doing it wrong, but how? The visualforce guide isn't very clear.