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
udayar_jayamudayar_jayam 

how to switch the record from one datatable to another datatable based on picklist value select

Hi All,

I have a VF Page to display two list named list1 and list2. In list1 i am having a picklist called "Status" which has two values named open and complete. In list1 if we select the picklist value "complete" then that record should move to list2. Here is my code but its not working , please guide me

 

public with sharing class sample {
public Integer numberOfRowToRemove1 { get; set; }
public List<Account> list1 { get; set; }
public List<Account> list2 { get; set; }
public string temp{get;set;}

public sampe()
{
list1 = [select id,name,accountnumber from Account];
list2 = [select id,name,accountnumber from Account];
}

public void find()
{

if(temp=='complete')
{
list2.add(0,list1.get(numberOfRowToRemove1));
list1.remove(numberOfRowToRemove1);

}

}
}
Page:
<apex:page controller="sample" >
<apex:variable value="{!0}" var="rowNumber1" />
<apex:outputPanel id="panelWithVar">
<apex:variable value="{!0}" var="rowNumber1" />
</apex:outputPanel>
<apex:pageBlock id="table1">
<apex:dataTable value="{!list1}" var="a" columnswidth="100px,100px" cellpadding="3" columns="4" border="1" width="1050px" bgcolor="#f5dcef" rowClasses="1" >
<apex:column value="{!a.Name}" headerValue="Customer Name" />
<apex:column value="{!a.AccountNumber}" headerValue="Number" width="100"/>
<apex:column headerClass="Status">
<apex:selectList id="selected_list" value="{!temp}" required="false" size="1">
<apex:selectOption itemvalue="None" itemLabel="--None--"/>
<apex:selectOption itemvalue="complete" itemLabel="complete"/>
<apex:selectOption itemvalue="Open" itemLabel="Open"/>
<apex:actionSupport event="onchange" reRender="Details,panelWithVar,table1,table2" action="{!find}"/>
<apex:param name="p1" value="{!rowNumber1}" assignTo="{!numberOfRowToRemove1}"/>
</apex:selectList>
<apex:variable var="rowNumber3" value="{!rowNumber1 + 1}" />
</apex:column>
</apex:dataTable>
</apex:pageBlock>

<apex:pageBlock id="Details">
<apex:pageBlockSection >
<apex:panelGroup >
<apex:dataTable value="{!list2}" var="a" columnswidth="50px,50px" cellpadding="4" border="1" >
<apex:column value="{!a.Name}" headerValue="Customer Name" width="100"/>
<apex:column value="{!a.AccountNumber}" headerValue="Address" width="100"/>
<apex:column headerClass="Status">
<apex:selectList id="selected_list" value="{!temp}" required="false" size="1">
<apex:selectOption itemvalue="None" itemLabel="--None--"/>
<apex:selectOption itemvalue="complete" itemLabel="complete"/>
<apex:selectOption itemvalue="Open" itemLabel="Open"/>
</apex:selectList>
</apex:column>
</apex:dataTable>
</apex:panelGroup>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:page>

 

digamber.prasaddigamber.prasad

On change of 'Status', what you can do is call an action, which will remove record from one list and assign the same to other list. And you can re-render both the lists.

 

Let me know if you have any other question.

 

Happy to help you!

 

Regards,

Digamber Prasad

udayar_jayamudayar_jayam

Thanks for your  reply @

digamber.prasaddigamber.prasad

Hi,

 

Inside find() method, I can see that value of variable 'temp' is always 'None'. Also, if you comment the if part, you will find that below line of code is throwing 'Attemp to de-reference a null object'.

 

I will suggest you to first fix this and probably after that we can take it forward.

 

Regards,

Digamber Prasad