0

Is it possible to somehow change the value for the apex:repeat dynamically on a page? What I mean is that I'm using apex:repeat to render table rows and as a value I have a List created in the custom controller. Something like this:

<apex:repeat value="{!data1}" var="d">
  <tr>
    <td>
      {!d.name1}
    </td>
  </tr>
</apex:repeat>

And I would like to change either the {!d.name1} to {!d.name2} or the value="{!data1}" to value="{!data2}" dynamically without reload of the page. So the page will be loaded, and I'll have a set of buttons above the table which will dynamically change the table (the value). Is it possible to do that on the Visualforce page, maybe using JS?

  • you can use ajax components like actionfunction – Mukesh Verma Jul 19 '16 at 16:47
2

It's not clear to me if what you need is to do so when the page is being rendered or after.

This is the approach to take if you were trying to do it during the rendering

<apex:repeat value="{!data1}" var="d">
  <tr>
    <td>
      <apex:outputText value="{!d.name1}" rendered="{!<A Condition>}" />
      <apex:outputText value="{!d.name2}" rendered="{!<Another Condition>}" />
    </td>
  </tr>
</apex:repeat>

If you were to do it after, and you want to avoid doing page reloads, then you are going to have to either use Javascript or do partial-rerenders via actionFunction or actionSupport tags.

If you choose Javascript, then you should head over to the JS StackExchange to learn how to use it (SFSE is not the right place).

If you want to use actionFunction or actionSupport I'll be happy to cook up some samples if/when you update your question with the proper context so I can write something that makes sense.

  • Thx for answer. I updated my question - I want to do so after the page was rendered. Using buttons on the page, I want to change the table dynamically. – mascot Jul 20 '16 at 5:45
  • mascot, per your update I see you want to do this using JS. If that's the case then you're in the wrong forum. While a lot of us know JS or jQuery, questions about those two scripting languages belong in the stackoverflow.com forum. – Sebastian Kessel Jul 20 '16 at 15:09
1

Sure, all you have to do is to place you apex:repeat inside an apex:outputPanel with some id (id="trial") then on your apex:commandbutton or in your apex:actionFunction from which you are calling the method for change your table place the following rerender="trial"

Hope that it helps :)

1

You can use dynamic binding in Visualforce page.

<apex:repeat value="{!listItems}" var="item">
    <tr>
        <td>
            {!item[attribute]}
        </td>
    </tr>
</apex:repeat>

In above attribute is the controller/extension property which you can set in controller/extension which will be invoke on click of the button.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.