+ Start a Discussion
rvkrvk 

how to display a link in a row only for one particular column value

I have a requirement need to display a table if any of the row value is acitive in one of the column called status now how to display a link(cancel) with in the same column that is next to acitve value.if user click on that link  status should turn to cancle and link should  disappear. Any thoughts....

Best Answer chosen by Admin (Salesforce Developers) 
Damien_Damien_

I would suggest building a wrapper class for your objects.  In your table used the rendered property for editing.  Below I am using the Case object just for example:

 

public List<MyWrapper> myWrappers{get;set;}
public class MyWrapper
{
  public Case myCase{get;set;}
  public boolean isActive{get;private set;}
  public MyWrapper(Case myCase)
  {
    this.myCase = myCase;
    isActive = false;
  }

  public void makeActive()
  {
    isActive = true;
  }

  public void makeInactive()
  {
    isActive = false;
  }
}
<apex:commandLink value="Cancel" action="{!this.makeInactive}" rendered="{!this.isActive}" rerender="mytable" />

All Answers

cloudmaniacloudmania

if My understanding is correct ,below may accomplish your requirement.

(keep in mind that you have to add jquerybase library in ur page)

<script>

function ToggleStatDiv()

{

('#main-div').hide('fast'); ('#status-div').show('fast');

}

</script>

function ToggleMainDiv()

{

('#main-div').show('fast'); ('#status-div').hide('fast');

}

</script>

<table>

<thead>

<tr>

<th>Status</th>

        </tr>

</thead>

        <tbody>

<tr>

<td>

<div id="main-div">

<a href="javascript&colon;void(0)" onclick="ToggleStatDiv();">Show Status</a>

</div>

<div id="status-div" style="display:none;">

{!Your Status}

<a href="javascript&colon;void(0)" onclick="ToggleMainDiv();">Cancel</a>

</div>

</td>

</tr>

</tbody>

</table>

Damien_Damien_

I would suggest building a wrapper class for your objects.  In your table used the rendered property for editing.  Below I am using the Case object just for example:

 

public List<MyWrapper> myWrappers{get;set;}
public class MyWrapper
{
  public Case myCase{get;set;}
  public boolean isActive{get;private set;}
  public MyWrapper(Case myCase)
  {
    this.myCase = myCase;
    isActive = false;
  }

  public void makeActive()
  {
    isActive = true;
  }

  public void makeInactive()
  {
    isActive = false;
  }
}
<apex:commandLink value="Cancel" action="{!this.makeInactive}" rendered="{!this.isActive}" rerender="mytable" />
This was selected as the best answer
Damien_Damien_

Made an adjustment to the Constructor of my Wrapper.  I forgot the parameter portion.

rvkrvk

It worked .Thank you so much. 

Damien_Damien_

Could you please mark the solution that worked for you so that others may see?

rvkrvk

there is an extension to the above requirement that is  a number datatyoe field exist in the  record when click on that link if the value in the number field is not with in the required range it should display an alert along with the buttons like continue or cancel the request. if the user click on continue the status should turn to cancelled or if the user selects cancel it should come back to the same page. could please let me know how this can be developed.

Damien_Damien_

You might want something similar to this:

 

//You may need to make a few modifications to be more directly for your purposes.

public class MyWrapper
{
  public Case myCase{get;set;}
  public boolean isActive{get;private set;}
  public MyWrapper(Case myCase)
  {
    this.myCase = myCase;
    isActive = false;
  }

  public void makeActive()
  {
    isActive = true;
  }

  public void makeInactive()
  {
    isActive = false;
  }

  public boolean getIsValid()
  {
    return //however this would be figured out.;
  }

  public PageReference continue()
  {
    //do work here
    return new PageReference('new url here');
  }
}
<apex:commandLink value="Cance" rendered="{!!this.isValid}" />
<apex:commandLink value="Continue" rendered="{!this.isValid}" />

 

 

rvkrvk

Thank you for replying back. Here an alert means a popup window that window should contain these buttons.I know really don't understand how to handle rendered field and  action methods from a wrapper class. 

Damien_Damien_

Well, you could do some javascript to get the values, but the quickest way to get to where you need with what I've given you already would be something like:

 

<apex:outputPanel id="alertPnl" rendered="{!this.isValid}">
  <script>
    alert('text in here');
  </script>
</apex:outputPanel>

 

There is definately better and more efficient ways, but this keeps you more along the line of what we've already built.  On the commandLinks add 

 

rerender="alertPnl"