+ Start a Discussion
Amol DixitAmol Dixit 

How to provide Pagination to VF page

Hi !

 

 

I wants to provide pagination to my Visual force page. How can I provide that??

 

 

VF Page:

 

<apex:page controller="CRUDModuleController">
<apex:form id="form">
<apex:pageBlock title="Modules">
<apex:pageMessages ></apex:pageMessages>
<apex:pageBlockButtons location="top">
<apex:commandButton value="New" action="{!addNew}"/>
</apex:pageBlockButtons>
<apex:pageBlockTable value="{!moduleList}" var="row">
<apex:column >
<apex:outputLink title="" value="/apex/editModule" style="font-weight:bold">Edit <apex:param name="msg" value="{!row.Name}"/></apex:outputLink>&nbsp;|&nbsp;
 <a href="javascript&colon;if (window.confirm('Are you sure?')) DeleteAccount('{!row.Id}');" style="font-weight:bold">Del</a>
 
</apex:column>
<apex:column value="{!row.Name}"/>
<apex:column headerValue="Module Name">
 <apex:outputLink value="/apex/DetailModule" >
                        <apex:outputField value="{!row.Name__c}"/>
                         <apex:param name="msg" value="{!row.Name}"/>
                        </apex:outputLink>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>

<apex:actionFunction action="{!DeleteAccount}" name="DeleteAccount" reRender="form" >
<apex:param name="accountid" value="" assignTo="{!selectedModuleId}"/>
</apex:actionFunction>
</apex:form>
</apex:page>

 

 

VF Class:

public class CRUDModuleController {


public List<module__c> moduleList { get; set; }

public string selectedModuleId { get; set; }

public CRUDModuleController() {

LoadData();
}

private void LoadData() {
moduleList = [Select id,name,Name__c from module__c];
}

public void DeleteAccount()
{
if (selectedModuleId == null) {

return;
}

module__c tobeDeleted = null;
for(module__c a : moduleList)
if (a.Id == selectedModuleId) {
tobeDeleted = a;
break;
}

if (tobeDeleted != null) {
Delete tobeDeleted;
}


LoadData();
}

public Pagereference addNew()
{
PageReference ref=new PageReference('/apex/addModule');
ref.setRedirect(true);
return ref;

}

}

 

Thank you !

 

 

Amol Dixit.

Best Answer chosen by Admin (Salesforce Developers)