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
rvkrvk 

custom picklist view and pagination

how  to create a pageblock table need to be filtered up on picklist view and  also  the table has to support pagination. 

Navatar_DbSupNavatar_DbSup

Hi,

 

Try the below code snippet as reference:

 

----------- Vf page------------

 

<apex:page controller="showdatawithnext" >
<apex:form >
<apex:selectList size="1" value="{!picklistvalue}" >
<apex:selectOption itemLabel="a" itemValue="a"></apex:selectOption>
<apex:selectOption itemLabel="b" itemValue="b"></apex:selectOption>
<apex:selectOption itemLabel="c" itemValue="c"></apex:selectOption>
<apex:selectOption itemLabel="s" itemValue="s"></apex:selectOption>
<apex:actionSupport event="onchange" action="{!calldisplay}" reRender="pp" />
</apex:selectList>
<apex:outputpanel id="pp">

<apex:pageBlock >
<Apex:pageBlockTable value="{!ct1}" var="k">
<apex:column ><apex:facet name="header">Name</apex:facet>{!k.name}</apex:column>
<apex:column ><apex:facet name="header">Email</apex:facet>{!k.email}</apex:column>
<apex:column ><apex:facet name="header">Mobile Phone</apex:facet>{!k.MobilePhone}</apex:column>
<apex:column ><apex:facet name="header">Birth Date</apex:facet>{!k.Birthdate}</apex:column>
</Apex:pageBlockTable>
</apex:pageBlock>


<table>
<tr>
<apex:repeat value="{!noofpage}" var="nn">
<td> <apex:commandLink action="{!display}" reRender="pp" ><apex:param value="{!nn}" name="sss" assignTo="{!pageno}"/> {!nn}</apex:commandLink></td>
</apex:repeat>
</tr>
</table>
</apex:outputpanel>
<apex:commandButton value="next" action="{!display1}" reRender="pp"></apex:commandButton>



</apex:form>


</apex:page>

 

 

---------------------- Apex controller --------------------

 

public class showdatawithnext

{

public integer count{get;set;}

public integer count1{get;set;}

public integer size1{get;set;}

public string picklistvalue{get;set;}

public integer indexfrom{get;set;}

public integer indexto{get;set;}

public integer remaining{get;set;}

public integer temp{get;set;}

public integer temp1{get;set;}

public list<contact> ct{set;get;}

public list<integer> noofpage{get;set;}

 

public integer pageno{get;set;}

public list<contact> ct1{set;get;}

 

 

public showdatawithnext()

{

  

   

    picklistvalue = 'a';

    ct=new list<contact>();

    calldisplay();

 

}

public void calldisplay()

{

     noofpage=new list<integer>();

    ct=[SELECT name,email,MobilePhone,Birthdate from contact];

    string query1='SELECT name,email,MobilePhone,Birthdate from contact where name like \''+picklistvalue+'%\'  limit 1000 ';

    system.debug('!!!!!!!!!!'+query1);

    ct= database.query(query1);

    system.debug('@@@@@@@@@@'+ct);

    count=ct.size();

    count1=ct.size();

    indexfrom=0;

    indexto=0;

    temp=0;

    size1=3;

    temp1=count/size1;

    temp=(math.mod(count,size1));

    count=0;

    if(temp>0)

    {

        for(integer i=1;i<=temp1+1;i++)

        {

            noofpage.add(i);

        }

    }

    else

    {

    for(integer i=1;i<=temp1;i++)

        {

            noofpage.add(i);

        }

    } 

    pageno=1;

   

    display();

}

public void display()

{

       if(pageno<=temp1+1)

       {

               ct1=new list<contact>();

               indexfrom=size1*(pageno-1);

               count=count+1;

               indexto=size1*pageno;

               if(indexto<=count1)

               {

                    for(integer i=indexfrom;i<indexto;i++)

                    {

                       if(ct[i]!=null)

                       {

                           ct1.add(ct[i]);

                       }

                     }

                }

                else

                {

                      indexto=((size1*(pageno-1))+temp);

                      for(integer i=indexfrom;i<indexto;i++)

                      {

                           if(ct[i]!=null)

                           {

                               ct1.add(ct[i]);

                           }

                      }

     

                }

 

   

    }

   

}

public void display1()

{

    if(pageno<=temp1)

    {

    pageno=pageno+1;

    display();

    }

    else

    {

        pageno=1;

    }

}

 

 

}

 

 Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

rvkrvk

Thanks for the reply. The standard set controller worked for my requirement.