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
IanM1963IanM1963 

Two lists of objects displayed in two separate columns

Hi,

 

Does anyone know how to do this? I thought it would be quite straightforward. I set up two datatables and two different queries in my controller but one (the second column) just doesn't show anything.

Is there a standard approach to displaying two lists of objects in two columns in VisualForce?

 

I can post code later but not sure how much it would help because I've described what I've done.

 

Regards,

 

Ian

Best Answer chosen by Admin (Salesforce Developers) 
Shashikant SharmaShashikant Sharma

There is no issue in dispalying two tables for lists of a object. You can show any number table, Please sahre your code. The satndard approach would be using only one query and prepare two lists out of it to be used for dispalying items on the VFP, that is to Save SOQL . But even if you have used two different SOQL there is no issue , your lists should come on VFP. Please sahre your code I think we can solve this issue.

All Answers

Shashikant SharmaShashikant Sharma

There is no issue in dispalying two tables for lists of a object. You can show any number table, Please sahre your code. The satndard approach would be using only one query and prepare two lists out of it to be used for dispalying items on the VFP, that is to Save SOQL . But even if you have used two different SOQL there is no issue , your lists should come on VFP. Please sahre your code I think we can solve this issue.

This was selected as the best answer
sravusravu

Hi,

 

Are you trying to query lists from two different objects and display them in the same datatable?

 

IanM1963IanM1963

Hi,

Sorry I'm late replying. I fixed it.

 

I think it was acombination of my newbiness, css, VF rendering and how I'd nested components. FOr some reason two dataTables refused to work but two repeaters were fine.

 

I thought I'd post what I'd done in case it helps anyone else.

 

It's rough and ready but it works...

 

 VF Page…


…

I have removed bits that aren't relevant

<apex:page id="theCal" controller="ShiftController" sidebar="false">

<apex:form id="theForm" ><br />
<apex:pageBlock id="theBlock">


<h1>Daily Shift Plan</h1>
<br />



 <div id="message">
 <apex:actionStatus startText="Saving to database..." id="status"   startStyle="color:red;font-size:20px;"  />
 </div>  
<div style="display:block;">
<div style="width:50%;position:relative;float:left;">
<br /><br />
<h1>Allocated Colleagues</h1>
<br />
    <apex:repeat value="{!dailyShifts}" var="aShift">
        
      
           
        <div class="dropZone" id="{!aShift.Id}" last-id="{!aShift.Id}">
          
           <span class="start-time">{!aShift.Start_Time__c}</span>
       
        
         <apex:detail rendered="{!IF(aShift.Colleague__c == null, false, true)}">  <div class="widget" sid="{!aShift.Id}" id="{!aShift.Colleague__c}">
                <b>Last Name</b>
          
            {!aShift.Colleague__r.Name}
               <br />
     
            
                <b>Mobile No.</b>
            
            {!aShift.Colleague__r.UK_Mobile_Number__c}
            
            <b>Shift:</b>
            {!aShift.Id}
            
            
            </div><!-- End widget --></apex:detail>
            
            </div><!-- End dropZone-->
           
           
   </apex:repeat>         
 

</div>

<div style="width:50%;float:left;">
<br /><br />
<h1>Unallocated Colleagues</h1>
<br />
<apex:repeat value="{!colleaguePool}" var="aColleague" >
                

                   
                <div class="pool">        <b>Colleague Pool</b>
                  
                   {!aColleague.Id}
               
                
                   <div class="widget" pool-id="{!aColleague.Id}">
                        <b>Last Name</b>
                  
                    {!aColleague.Name}
                       <br />
             
                    
                        <b>Mobile No.</b>
                    
                    {!aColleague.UK_Mobile_Number__c}
                    </div><!-- End widget -->
                    
                    </div><!-- End dropZone-->
                   
    
           </apex:repeat>  
</div>       
 </div><!--End of container-->  
 </apex:pageBlock>     
    </apex:form>

</apex:page>

 

 

And here is the controller - well, the methods that get the lists..

 

//Getter Methods

    public List<Daily_Shift__c> getDailyShifts()
    {
        if (dailyShifts == null)
        {
           // TODO: This query needs refining to get all shifts for one site on one week commencing...
           List<Daily_Shift__c> theseDailyShifts = new List<Daily_Shift__c>();
            theseDailyShifts = Database.query('select Id, Site__c, Site__r.Name, Colleague__c, Colleague__r.Name, Colleague__r.Worker_First_Name__c, Colleague__r.Colleague_Name__c, Colleague__r.UK_Mobile_Number__c, Start_Time__c, Shift_Date__c from Daily_Shift__c order by Start_Time__c asc');
            return theseDailyShifts;
        }
        else
        {
        
            return dailyShifts;
        }
    }


public List<Colleague__c> getColleaguePool() 
           {  
        
                   try 
                   {
                    soql = getSoql();
                       
                       colleagues = Database.query(soql); 
                       System.debug('Size of result:' + colleagues.size());
                       if (colleagues.size() == 0)
                       {
                           colleagues = null;
                       }
                   }
                   catch (Exception e)
                   {
                       ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Please choose site from the pick list!'));
                    }
                return colleagues;    
            }
        
    
     
             public string getSoql()
                {
                    soql = 'select Id, Name, Account__c, Adapt_Ref__c, Agency_Type__c, ColleagueID__c, Colleague_Name__c, Colleague_Status__c, UK_Mobile_Number__c, Worker_First_Name__c, Worker_Role__c,  Comments__c from Colleague__c where Id  not in (select Colleague__c from Daily_Shift__c) and   Account__c != null';
                    return soql;       
                }

 

And finally the page it renders - I've used jQuery with drag and drop ui stuff to make it easy for people to get folk from the pool on the right and place them in a shift on the left....

 

Click Here to See Page