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
brielea1984brielea1984 

Dynamic Table - Add child records to each row?

So I've implemented many many time the use case of for X Parent record, add multiple children on one page with an add/delete button as seen here: http://michaelwelburn.com/2013/10/21/how-to-create-a-reusable-editable-table-in-visualforce/

Is it possible to create this table in a loop for multiple parents?

As in, in my controller I have a SOQL query to return a list of Opportunities based on a condition, ex: [SELECT Name FROM Opportunity WHERE .....]
I want, for each Opportunity returned in the query, to display the list of opportunities. Then for each Opportunity, render an add/delete button to add/delete child records for that Opportunity.

Should appear like, on a visualforce page for the Account Object:
Opportunity 1 +/- (output)
     + Custom Object Record 1 (input)
     + Custom Object Record 2 (input)
Opportunity 2 +/-
    + Custom Object Record 3
Opportunity 3 +/-
     + Custom Object Record 4
     + Custom Object Record 5
and so on...
                       Save All Custom Object Records

Opportunity lookup on Custom Object Record saved with the Opportunity Id above them in the hierarchy in the table.

I tried creating a table with repeat values to list the "Opportunities", and then in the next table row add the code for adding a child record. This simply duplicates the same list, so when I click "add row", a row is added in table rows for that process. The button has the same value every time it's repeated, so I'm not sure how to dynamically assign a button value since the add button will appear X number of times. 

I know apps like Grid Buddy can achieve this, but this needs to be built natively.

If anyone can point me to any examples of this successfully implemented I'd be much appreciative. Barring that, any pointers would be awesome. 

Thanks!