You need to sign in to do that
Don't have an account?
umair ayaz
A function to reorder the table
Hi saleforce experts I am stucj with a small problem where i want to reorder my table according to order number so right now i have created a order number field and have ordered the table according to order number and the issue i am facing right now is for example if i change the order number 20 to order number 5 the record in order number 5 should change to order number 6 which means all the records between order number 5 to order number 20 should be added by 1. I have added my visualforce page codes and my controller codes below. please guide me on how it could be done. Thanks in advance
My visualforce code
My apex code
My visualforce code
<apex:page controller="OrderAccountController" > <apex:form> <apex:pageBlock title="List of accounts"> <apex:pageBlockTable value="{!account}" var="a"> <apex:column value="{!a.Name}"/> <apex:column value="{!a.Industry}"/> <apex:column value="{!a.Type}"/> <apex:column headerValue="Order Number"> <apex:inputField value="{!a.order__c}"/> </apex:column> </apex:pageBlockTable> </apex:pageBlock> <apex:commandButton value="Reorder" action="{!save}" /> </apex:form> </apex:page>
My apex code
public class OrderAccountController { public List <Account> account=new List <Account>(); public Account act{get;set;} public List <Account> getAccount() { account = [SELECT Id, Name, Site, Type, accountNumber, CustomerPriority__c, order__c, industry FROM Account order by order__c ]; return account; } public PageReference save() { try { update account; } catch(Exception e){ System.debug('Exception occurred '+String.valueOf(e)); } return NULL; } }
May I suggest you please refer the below link for reference.
- https://salesforce.stackexchange.com/questions/61215/dragging-and-reordering-datatable-pageblocktable-rows
- https://salesforce.stackexchange.com/questions/25072/sorting-columns-in-pageblocktable
Hope it will be helpful.Thanks
Rahul Kumar