You need to sign in to do that
Don't have an account?

How to dynamically add rows in visualforce page
Hi All,
I have a page within which there a button "Add Filter". Beneath this button are some filters like:
Select Object(this is a select list containing all salesforce object)---Select Field(this is also a select list containing all fields of salesforce selected salesforce object)------Textbox(this is a textbox)------Remove(this is a button which should remove row).
When the user clicks on Add filter, a replica of all above filter items should be added beneath the current filter and on click of Remove button the respective filter should be removed.
Any one who as idea/sample code regarding this please help.
Thank you!
Regards,
Lakshman
Laksman,
1. Create a wrapper class with the fields, and when page is loaded add one empty object to List<Wrapper>, and bind the same to datatable/pageblock.
2. When user clicks the "Add" then again create a copy(clone) the wrpper item and add it to the list and bind the table with rerender.
3. if user clicks on delete then you will be having the Index of item in list just remove the same.
try with this code.
Your way is fine. I have done this in a bit different way, here is my code:
Apex Class:
Visualforce Page:
I am able to add elements on click of add row.
What do you think about this?
Let me know your thoughs.
Thank you!
Hi Lakshman,
I tried your code and I am able to add rows dynamically.
Now the problem is, these rows I want to use for inserting custom object records. But, I am able to insert only last row record and not the previous one. Can you please tell me why this happening?
Thanks.
Please let me know your code so that I could figure it out.
Regards,
Lakshman
Thanks Lakshman.
I have 'Teacher Experience' as custom object that I want to insert dynamically.
If I add 3 rows, then I want to insert 3 records. Please help me out to do this.
Thank you very much Lakshman, your code was really helped for adding new rows dynamically.
I have3fieldsononerow, 1. Fields(PickList), 2. Operator(Picklist) 3. Value(TextBox) . But
i am facing the refresh problem, when the user entered first row data and click on "Add Row" Button, successfully Added New Row , But First row data will getting cleared.
How can i overcome this issue.... Please help me .
Thanks,
Yarram
You could add a saving logic within the addRow method so that everything that has been modified is saved before the page refreshes.