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
Hari@RockzsHari@Rockzs 

Swapping Data in DataTable

Hi Friends,

 

 

How to swap data in datatable can u any body help me! to swap records we have to use checkbox to select records

 

 

thanku

 

 

bob_buzzardbob_buzzard

Can you explain a bit more about what swapping data means?  E.g. does it change the presentation of the table, the content of the table or something else.

Hari@RockzsHari@Rockzs

Scenario:

 

                          I have data table,in one column i have checkbox,and in another column i have Account Names,and i have one button on the top of table,i can select any two of Accountnames by checking checkboxes and cilck the button then the two records(places of that records in the data table) are swapped in the datatable itself.

 

                                                                  Checkbox        Name

                                                                           []                 A1

                                                                           []                 A2

 

                                                                                 [SWAP]

bob_buzzardbob_buzzard

Presumably the checkbox does not form part of the account record? That being the case, you will need to use our old friend the wrapper class to combine the checkbox and the account record.

 

Then you'd back your datatable with a list of the wrapper classes, pulling the name and the checkbox from the wrapper class instance.

 

When the button is clicked, you can traverse your list of wrapper classes to determine which have the checkbox ticked.  Once you've found that, swap the wrapper accounts, unset the checkboxes and redraw the table.

Hari@RockzsHari@Rockzs

can u please give me suggestion to get selected records only displayed in another page in same scenario.

 

 

Hari@RockZ

bob_buzzardbob_buzzard

You'll need to pass the record ids on the URL of the new page.  

 

E.g. if you have built a list of accounts to display on the new page in your action method named 'theAccs', your action method needs to finish similar to the following:

 

 

 

   PageReference result=Page.MyNewPage;
   Integer idx=0;
   while (idx<theAccs.size())
   {
      result.getParameters().put('AccountId_'+(idx+1), theAccs[idx]);
   }

   return result;

 and your target page needs to pull these from the URL.

 

Hari@RockzsHari@Rockzs

ThanX BOB

 

Iam getting Error with this,

 

         Can u explain more please..................

 

 

Hari@RockZ

bob_buzzardbob_buzzard

Not unless you tell me what the error you are getting is I'm afraid.