+ Start a Discussion
RovRov 

dynamically remove row from data table

I have a dataTable and one of the column is a checkbox. Onchange of the checkbox, an update is made to the database. 

If the checkbox is made true on say row1, how can I remove that row1 from the vsiaulforce page display. I am not removing it from the database, just not wanting to show in the VFP.

<br/></br>

I don't want to render, becuase that leaves an empty row.

This is my code. 

<pre>

public class dataTableCon {

    public Id accountId { get; set; }
    
    ID aid = apexPages.currentPage().getParameters().get('aid');
    public List<Account> accounts ;
   
    public dataTableCon (){
     
   
    }
   

    public List<Account> getAccounts() {

        if(accounts == null) accounts = [select name, owner.name,hidden_field__c from account limit 10];

        return accounts;

    }

   

    public void saveAccount(){

    system.debug('&****************');
     Map<Id,Account> map_Accounts = new Map<Id,Account>(accounts);

        update map_Accounts.get(accountid);

    }
}

</pre>

VFP

<pre>

<apex:page controller="dataTableCon" id="page">
   
<apex:form >
<apex:pageBlock id="theBlock">
   
    <apex:dataTable value="{!accounts}" var="account" id="theTable" rowClasses="odd,even" styleClass="tableClass">
   
        <apex:column >
            <apex:facet name="header">Private</apex:facet>
             <apex:inputCheckbox value="{!account.hidden_field__c}" >
             <apex:actionSupport event="onchange" action="{!saveAccount}" reRender="theBlock">
                <apex:param name="accountId" value="{!account.Id}" assignTo="{!accountId}"/>
             </apex:actionSupport>            

           </apex:inputCheckbox>           
        </apex:column>
   
       
        <apex:column >
            <apex:facet name="header">Name</apex:facet>
            <apex:outputText value="{!account.name}" / >
        </apex:column>
   
        <apex:column >
            <apex:facet name="header">Owner</apex:facet>
            <apex:outputText value="{!account.owner.name}"  />
        </apex:column>
       
    </apex:dataTable> 
   
    </apex:pageBlock>
    </apex:form>
</apex:page>

</pre>
Ankit Gupta@ DeveloperAnkit Gupta@ Developer
Hi,

Try the below code snippet

VF page
----------------------
<apex:page controller="dataTableCon" id="page">
  
<apex:form >
<apex:pageBlock id="theBlock">
     <apex:dataTable value="{!accounts}" var="account" id="theTable" rowClasses="odd,even" styleClass="tableClass">
  
        <apex:column >
            <apex:facet name="header">Private</apex:facet>
            <apex:actionRegion >
             <apex:inputCheckbox value="{!account.hidden_field__c}" >
             <apex:actionSupport event="onchange" action="{!saveAccount}" reRender="theBlock">
                <apex:param name="accountId" value="{!account.Id}" assignTo="{!accountId}"/>
             </apex:actionSupport>           
   
           </apex:inputCheckbox>          
           </apex:actionRegion>
        </apex:column>
  
      
        <apex:column >
            <apex:facet name="header">Name</apex:facet>
            <apex:outputText value="{!account.name}" / >
        </apex:column>
  
        <apex:column >
            <apex:facet name="header">Owner</apex:facet>
            <apex:outputText value="{!account.owner.name}"  />
        </apex:column>
      
    </apex:dataTable>
 
  
    </apex:pageBlock>
    </apex:form>
</apex:page>
--------------------

Apex class

-------------------------

public class dataTableCon {

    public Id accountId { get; set; }
   
    ID aid = apexPages.currentPage().getParameters().get('aid');
    public List<Account> accounts ;
  
    public dataTableCon (){
    
  
    }
  

    public List<Account> getAccounts() {

       accounts = [select name,hidden_field__c, owner.name from account where hidden_field__c!= true limit 10 ];

        return accounts;

    }

  

    public void saveAccount(){

    system.debug('&****************');
     Map<Id,Account> map_Accounts = new Map<Id,Account>(accounts);

        update map_Accounts.get(accountid);

    }
}
Damien Phillippi033905702927186443Damien Phillippi033905702927186443
<pre>
public List<Account> getAccounts()
{
  return [SELECT Name, Owner.Name, Hidden_Ffield__c FROM Account WHERE Hidden_Field__c = false LIMIT 10];
}
</pre>
RovRov
Thanks for the response.