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
sarvesh001sarvesh001 

Datatable..

Hi,
I am using datable to show data int able formate in vf page . If it showing 10 records
My requirement is when i click the button the corresponding recod should be  in editable mode in same vf page .



Can any one help me out for this.....


Thanks,
sarvesh
Best Answer chosen by sarvesh001
Ravi NarayananRavi Narayanan

1)Use Wrapperclass (Sobject,Boolean)
2)Use apex:param for passing the selected record from page to Controller .
3) make that boolean variable for this record as TRUE.

 

VF PAge:
boolean true-- render inputField
false-render outputField

All Answers

Ravi NarayananRavi Narayanan

1)Use Wrapperclass (Sobject,Boolean)
2)Use apex:param for passing the selected record from page to Controller .
3) make that boolean variable for this record as TRUE.

 

VF PAge:
boolean true-- render inputField
false-render outputField

This was selected as the best answer
sarvesh001sarvesh001
Hi Ravi Narayanan,

Can you share sample code ....


Thanks,
Sarvesh.
sarvesh001sarvesh001

Hi Ravi Narayanan,
I have tried this one in demo version.
I have posted my code when i clicked the checkbob  corresponding row  is in editable mode .
But the issue is it showing same records repetedly 
Can you suggest me...


<apex:page StandardController="Contact" extensions="RowEditingcontroller">

  <apex:pageMessages />

    <apex:form id="theForm">
        <apex:pageBlock Title="ALL CONTACTS FOR ROW EIDTING" id="pb">
          
           <apex:commandButton value="Save" action="{!tosave}" id="saveButton"  />
 
           <apex:outputPanel >

         

              <apex:pageBlockTable value="{!Contacts}" var="c" cellpadding="2" border="1"  rowClasses="odd,even" styleClass="tableClass" id="opp_table">
                 
                  <apex:column headerValue="Edit" >
                     <apex:inputcheckbox value="{!c.selected}">
                       <apex:actionSupport event="onclick" action="{!getSelected}"  rerender="pb" />
                     </apex:inputcheckbox>&nbsp;
                  </apex:column>
                   <apex:column headerValue="Contact name" >
                  
                    <b><apex:outputField rendered="{!IF(c.selected==true,false,true)}" value="{!c.con.Name}"/> </b>   
                       <apex:inputfield rendered="{!IF(c.selected==true,true,false)}" value="{!c.con.Name}"/>
                      </apex:column>
                 <apex:column headerValue="Contact No" >
                    <apex:outputfield rendered="{!IF(c.selected==true,false,true)}" value="{!c.con.MobilePhone}" />
                   <apex:inputfield rendered="{!IF(c.selected==true,true,false)}" value="{!c.con.MobilePhone}" />
                 </apex:column>
                 <apex:column headerValue="Email">
                   <apex:outputField rendered="{!IF(c.selected==true,false,true)}" value="{!c.con.Email}"/>
                    <apex:inputField rendered="{!IF(c.selected==true,true,false)}" value="{!c.con.Email}"/>
                 </apex:column>
               <apex:inlineEditSupport event="ondblClick"  showOnEdit="saveButton"/>
               

         </apex:pageBlockTable>

      </apex:outputPanel>

     </apex:pageBlock>
  </apex:form>
 
  </apex:page>


---------------------------------------------controller------------------------------------
public class RowEditingcontroller {

     //All property....

     public Contact contact{get;set;}
     public Id Id{get;set;}
     List<contactwrapper> contactList = new List<contactwrapper>();
     List<Contact> selectedContacts = new List<Contact>();

     //constructor....

     public RowEditingcontroller(ApexPages.StandardController controller) {
   
       

      }

     //displaying contact pageBlock table....
     
     public  List<contactwrapper> getContacts() {
   
        for(Contact c: [select Id,Name,Account.Name,MobilePhone,Email from Contact order by createdDate desc limit 1  ])
    
              contactList.add(new contactwrapper(c));
              return contactList;
          }

       //all selected contacts...for edit...      
     public PageReference getSelected() {
   
         selectedContacts.clear();
         for(contactwrapper conwrapper: contactList)
            if(conwrapper.selected == true)
      
            selectedContacts.add(conwrapper.con);
      
            return null;
        }
       
       
     public List<Contact> GetSelectedContacts(){
   
        if(selectedContacts.size()>0)
        return selectedContacts;
        else
       // ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Please select at least one Contact.'));
        return null;
    }
    
    //saving edited value...
  
      public PageReference tosave() {
      if(selectedContacts.size()>0){
     
        update selectedContacts;
        PageReference RowEditing=new PageReference('/apex/RowEditing');
        RowEditing.setRedirect(true);
        return RowEditing;
        }
        else{
        ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Please select at least one Contact.'));
         return null;
        }
      
       }
   
    //wrapper class...
   
    public class contactwrapper
    {
        public Contact con{get; set;}
        public Boolean selected {get; set;}
        public contactwrapper(Contact c)
        {
            con = c;
            selected = false;
        }
    }
}