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
DeepikareddyDeepikareddy 

Hi.. folks , got stucked in a small functionality of sample development

Note: as per my code all the rows are getting rendered, on clicking of the Edit button,but the requirement is ::
1)on  click of the Edit button, that particular row should have to change to input , how it can be acheived.
Controller : 
public class testingclass {

public string xmlstring{get;set;}
 public string testingval{get;set;}
 public List<string> lsttestingval{get;set;}
 public boolean  indexSel{get;set;}
 public boolean anyBooleanValue{get;set;}
 
 public testingclass(){
  anyBooleanValue =true;
  lsttestingval = new list<string>();
  lsttestingval.add('Red');
    lsttestingval.add('Blue');
    lsttestingval.add('Yellow');
    
  }
  
   public void edit(){
   
   anyBooleanValue =False;
   }
   
   public void delet(){
   
  system.debug(lsttestingval.size());
    }
  
}
V.f page:
<apex:page controller="testingclass">
<apex:form >
    <table style="width:100%">
  <tr>
    <th>name</th>
    <th>Edit</th>
    <th>Delete</th>
  </tr>
<apex:variable var="cnt" value="{!0}" /> 
 <apex:repeat var="a" value="{!lsttestingval}"> 
 <tr>
     <td>
      <apex:outputPanel rendered="{!anyBooleanValue}" >{!a}</apex:outputPanel>
      <apex:outputPanel rendered="{!!anyBooleanValue}" ><apex:inputText /></apex:outputPanel>
      <!--<apex:outputPanel rendered="{!!anyBooleanValue && cnt == !indexSel}"><apex:inputText value="{!a}"/></apex:outputPanel> --->
     </td>
     <td><apex:commandbutton action="{!Edit}" value="Edit" /></td>
      <td><apex:commandbutton action="{!delet}" value="Delete" /></td>
      </tr>
      <apex:variable var="cnt" value="{!cnt+1}"/>
     </apex:repeat>
 
</table>
   
   </apex:form>
</apex:page>



Before click on edit buttonAfter clicking on the Edit button//please provide me solution that only that particular rwo should have to render.. thnks in advance
Best Answer chosen by Deepikareddy
itzmukeshy7itzmukeshy7
Here is working code:
Apex Controller:
public with sharing class Tests {

    public String xmlstring{get;set;}
    public String testingval{get;set;}
    public List<String> lsttestingval{get;set;}
    public Boolean indexSel{get;set;}
    public Integer editRow{get;set;}
    public Integer deleteRow{get;set;}

    public Tests(){
        editRow = -1;
        deleteRow = -1;
        lsttestingval = new List<String>();
        lsttestingval.add('Red');
        lsttestingval.add('Blue');
        lsttestingval.add('Yellow');
    }

    public PageReference editItem(){
        System.debug('editRow: ' + editRow);
        return null;
    }

    public PageReference deleteItem(){
        System.debug('deleteRow: ' + deleteRow);
        lsttestingval.remove(deleteRow);
        System.debug(lsttestingval.size());
        return null;
    }
}



VF Page:
<apex:page controller="Tests">
  <apex:form id="form">
    <table style="width:100%">
      <tr>
        <th>Name</th>
        <th>Edit</th>
        <th>Delete</th>
      </tr>

      <apex:variable var="cnt" value="{!0}" />
      <apex:repeat var="item" value="{!lsttestingval}">
        <tr>
          <td>
            <apex:outputPanel rendered="{!cnt != editRow}">
              {!item}
            </apex:outputPanel>
            <apex:outputPanel rendered="{!cnt == editRow}">
              <input value="{!item}" />
            </apex:outputPanel>
          </td>
          <td>
            <apex:commandbutton action="{!editItem}" value="Edit" reRender="form">
              <apex:param name="editRow" value="{!cnt}" assignTo="{!editRow}" />
            </apex:commandbutton>
          </td>
          <td>
            <apex:commandbutton action="{!deleteItem}" value="Delete" reRender="form">
              <apex:param name="deleteRow" value="{!cnt}" assignTo="{!deleteRow}" />
            </apex:commandbutton>
          </td>
        </tr>
        <apex:variable var="cnt" value="{!cnt+1}" />
      </apex:repeat>
    </table>
  </apex:form>
</apex:page>

All Answers

itzmukeshy7itzmukeshy7
Play around the index of the edit button row, that we definitely need to use in rendering the input elements, so basically the input field rendering will be if the current button clicked and the current row index is same, also we need to store the Edit button row index as well to track the clicked row.
DeepikareddyDeepikareddy
hi ,Can u please help me with the Sample code.. thanks in advance.. 
itzmukeshy7itzmukeshy7
Here is working code:
Apex Controller:
public with sharing class Tests {

    public String xmlstring{get;set;}
    public String testingval{get;set;}
    public List<String> lsttestingval{get;set;}
    public Boolean indexSel{get;set;}
    public Integer editRow{get;set;}
    public Integer deleteRow{get;set;}

    public Tests(){
        editRow = -1;
        deleteRow = -1;
        lsttestingval = new List<String>();
        lsttestingval.add('Red');
        lsttestingval.add('Blue');
        lsttestingval.add('Yellow');
    }

    public PageReference editItem(){
        System.debug('editRow: ' + editRow);
        return null;
    }

    public PageReference deleteItem(){
        System.debug('deleteRow: ' + deleteRow);
        lsttestingval.remove(deleteRow);
        System.debug(lsttestingval.size());
        return null;
    }
}



VF Page:
<apex:page controller="Tests">
  <apex:form id="form">
    <table style="width:100%">
      <tr>
        <th>Name</th>
        <th>Edit</th>
        <th>Delete</th>
      </tr>

      <apex:variable var="cnt" value="{!0}" />
      <apex:repeat var="item" value="{!lsttestingval}">
        <tr>
          <td>
            <apex:outputPanel rendered="{!cnt != editRow}">
              {!item}
            </apex:outputPanel>
            <apex:outputPanel rendered="{!cnt == editRow}">
              <input value="{!item}" />
            </apex:outputPanel>
          </td>
          <td>
            <apex:commandbutton action="{!editItem}" value="Edit" reRender="form">
              <apex:param name="editRow" value="{!cnt}" assignTo="{!editRow}" />
            </apex:commandbutton>
          </td>
          <td>
            <apex:commandbutton action="{!deleteItem}" value="Delete" reRender="form">
              <apex:param name="deleteRow" value="{!cnt}" assignTo="{!deleteRow}" />
            </apex:commandbutton>
          </td>
        </tr>
        <apex:variable var="cnt" value="{!cnt+1}" />
      </apex:repeat>
    </table>
  </apex:form>
</apex:page>
This was selected as the best answer
DeepikareddyDeepikareddy
Thank for your help..! marked as best answer.. !