2

I have VF Page to display Today and NextDay records which is stored in another custom object.In that list my client wants the functionally to move the today's record to the NextDay table by clicking the "Back to Next Day" button. When clicking on this button "Back to Next Day" it must add that record as a first record in Next Day table.I have attached the screenshot for this. Kindly give me some idea to achieve this. Thanks in advance.

Screenshots:

Step 1:

enter image description here

Step 2:

enter image description here

Regards,

Lavanya.

5

You can create a method that gets a number of entry in the target list and push it to another list. Then remove this entry from the first list:

Controller:

public with sharing class MyClass {

    public Integer numberOfRowToRemove1 { get; set; }
    public Integer numberOfRowToRemove2 { get; set; }

    public List<Account> list1 { get; set; }
    public List<Account> list2 { get; set; }

    public test2(){
        list1 = [select id, name from account limit 3];
        list2 = [select id, name from account limit 3 offset 3];
    }

    public PageReference swapObjectList1(){
        list2.add(list1.get(numberOfRowToRemove1)); 
        list1.remove(numberOfRowToRemove1); 
        return null;
    }

    public PageReference swapObjectList2(){
        list1.add(list2.get(numberOfRowToRemove2)); 
        list2.remove(numberOfRowToRemove2); 
        return null;
    }
}

Page:

<apex:page controller="MyClass">
<apex:form >

<apex:variable value="{!0}" var="rowNumber1" />
<apex:variable value="{!0}" var="rowNumber2" />


<!-- Here we will use an extra variable to define a row number -->
<apex:outputPanel id="panelWithVar">
    <apex:variable value="{!0}" var="rowNumber1" />
    <apex:variable value="{!0}" var="rowNumber2" />
</apex:outputPanel>

<apex:pageBlock title="List 1">
<apex:pageBlockTable value="{!list1}" var="item" id="list1">
    <apex:column value="{!item.name}" width="20%"/>
    <apex:column>
        <apex:commandButton action="{!swapObjectList1}" value="Push to list 2" reRender="list1,list2,panelWithVar">
            <apex:param name="p1" value="{!rowNumber1}" assignTo="{!numberOfRowToRemove1}"/>
        </apex:commandButton>
        <apex:variable var="rowNumber1" value="{!rowNumber1 + 1}" />
    </apex:column>
</apex:pageBlockTable>
</apex:pageBlock>


<apex:pageBlock title="List 2">
<apex:pageBlockTable value="{!list2}" var="item" id="list2">
    <apex:column value="{!item.name}" width="20%"/>
    <apex:column>
        <apex:commandButton action="{!swapObjectList2}" value="Push to list 1" reRender="list1,list2,panelWithVar">
            <apex:param name="p2" value="{!rowNumber2}" assignTo="{!numberOfRowToRemove2}"/>
        </apex:commandButton>
        <apex:variable var="rowNumber2" value="{!rowNumber2 + 1}" />
    </apex:column>
</apex:pageBlockTable>
</apex:pageBlock>

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

Here is the result:

enter image description here

And after clicking on the "Push to list 2":

enter image description here

7
  • Can we add the selected record as the first record of the List2. Now the record is adding as a last record in List2. Nov 12 '13 at 9:20
  • 1
    I think yes. You need to use index parameter of the .add() function, read more about index: list1.add(0, list2.get(numberOfRowToRemove2)); The 0 is always the first position in the list. Try it. Nov 12 '13 at 9:25
  • I have one more question. Sorry for troubling you too much. I have one more button called "Postpone".On clicking the button a calendar should popup in which the user should select the date, thereby the corresponding data should get stored on the selected date. Nov 12 '13 at 10:44
  • 1
    @LavanyaSanathkumar You can use a custom field of type Date and on the visualforce page use apex:inputField value="{!object.dateField__c}" It will generate a datepicker automatically. Nov 12 '13 at 11:28
  • I have one more question to ask you, above example which you have given perfectly fit for my requirement but only thing which needs to be added in this, each table should contain only eight records. If I am going to push the record from 1st table to 2nd table, 9th record of the 2nd table has to move to the 3rd table. Like that the process should be going on.Could you please help me out in this. Nov 13 '13 at 9:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.