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
John NeffJohn Neff 

visualforce "Grid" with junction objects?

Hello, 

I have a junction object called "Vendor Agreement" that is a junction between my Campaigns and a custom field object called "Vendors". 

I am trying to create a VF page that is laid out like a grid - where the Campaigns are the columns and the Vendors are the rows, and data from each Junction object populates in each cell.  For example if column 2 was the campaign "Widgets" and Row 2 was the vendor "Acme", I want to pull data from the Junction Object that exists between "Acme" and "Widgets" into Row 2, Column 2.  

Here is what I have so far, I just can not figure out how to render the data so that data is only displayed if on the Vendor Agreement object the "Vendor" lookup matches the value in column 1, and  the "Campaign" lookup matches the value in row 1. 

Am I even a little bit on the right track? 

Here is my controller: 
 
public class piPricingController{ 

    public List<Campaign> listOfOffers {get; set;}
    public List<PI_Vendor__c> listOfVendors {get; set;}
    public Campaign Offers {get; set;}
    public PI_Vendor__c Vendors {get; set;}
    
    public PageReference saveOF(){
    UPDATE listOfOffers;
    return null;
    }

public piPricingController(){ 
    listOfOffers = [Select id, name, (Select id, name, Partner_Name__c, Price_per_Call__c, Charge_Time_Threshold__c, Status__c  FROM Vendor_Addenda__r WHERE Vendor_Type__c = 'PI Vendor') FROM Campaign WHERE isActive = TRUE ORDER BY Name ASC];
    listOfVendors = [Select id, Name, (Select id, name, Partner_Name__c, Price_per_Call__c, Charge_Time_Threshold__c, Status__c  FROM Vendor_Addeda__r WHERE Vendor_Type__c = 'PI Vendor') FROM PI_Vendor__c WHERE Type__c = 'PI Vendor' ORDER BY Name Asc];

}
}

and here is my page: 
 
<apex:page controller="piPricingController">
<html>
<table cellpadding="5" style="border-collapse: collapse;table-layout:fixed" border="1">
<tr width="450">
<td width="450"> </td>
<apex:repeat value="{!listOfOffers}" var="a">
<td width="450"> {!a.name}</td>
</apex:repeat>
</tr>
<apex:repeat value="{!listOfVendors}" var="v">
<tr>
<td width="450">{!v.name} </td>
<apex:repeat value="{!listOfOffers}" var="va">
<td width="450">DATA RENDERED IF VENDOR MATCHES VALUE IN COLUMN 1 AND CAMPAIGN MATCHES DATA IN ROW 1 </td>
</apex:repeat>
</tr>
</apex:repeat>
</table>
</html>
</apex:page>


 
NagendraNagendra (Salesforce Developers) 
Hi John Neff,

Please refer to the below post for similar kind of issue.
http://salesforce.stackexchange.com/questions/133412/create-junction-records-through-a-grid-ui-for-two-objects,

Hope it helps.

Best Regards,
Nagendra.P