+ Start a Discussion
Mahendiran JayavarmaMahendiran Jayavarma 

Filter records using dropdown list in Pageblocktable

Hi,

 

Please guide me for filtering records in pageblocktable using dropdonlist.

 

I tried to implement using following code. But I could not  implement. So Please help me.

 

 

Controller:

 

public class ActivityController 
{

    public PageReference Search() {
    return null;
        }

Task Task;

public Task getTask() {
      if(Task == null) Task = new Task ();
      return Task ;
   }

    Public Task[] getActivities()
    { 
      
   
      return [Select id, subject,activitydate,owner.name,pro__Billable_Hrs__c,pro__Rate_Hrs__c,pro__Billable_Amount__c from Task];
    }


 
}

 

Apex page:

 

<apex:page controller="ActivityController"  >
 <apex:sectionHeader title="Invoice Generate" />

 <apex:form >
<apex:pageBlock >

<apex:pageBlockSection title="Search Task" columns="4" >


<apex:inputField id="Taskstatus" value="{!Task.status}" style="width:150px;"/> 

<apex:commandButton value="Search" action="{!Search}"/>


</apex:pageBlockSection>
<apex:pageBlockSection title="Search Result" columns="1" >
<apex:pageBlockTable value="{!Activities}" var="a" width="750">
  <apex:column >
                        <apex:facet name="header">Select</apex:facet>
                        <apex:inputCheckbox value="{!a.Id}" />
                </apex:column>

<apex:column value="{!a.subject}" rendered="true"/>
<apex:column value="{!a.owner.name}"/>
<apex:column value="{!a.Billable_Hrs__c}"/>
<apex:column value="{!a.Rate_Hrs__c}"/>
<apex:column value="{!a.Billable_Amount__c}"/>
</apex:pageBlockTable>

</apex:pageBlockSection>
</apex:pageBlock></apex:form>
</apex:page>

 

Help me asp.

 

Thanks,

Mahendiran

rmehrmeh

Hi Mahendiran,

 

I would suggest you to use a custom picklist instead of using standard piclikst.

 

================= VF Page==============================

 

 <apex:selectList size="1" id="txtStatus" value="{!strTaskStatus}">
 <apex:selectOptions value="{!TaskStatus}"/>
 </apex:selectList>

 

 

===================== end VF page=======================

 

 

==============Apex Controller=============================

public String strTaskStatus{get;set;}

 public List<SelectOption> getTaskStatus(){
        Schema.DescribeFieldResult F =  Task.Status.getDescribe();
        List<Schema.PicklistEntry> P = F.getPicklistValues();
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('','--All--'));
        for(Integer i = 0; i < P.size(); i++){
            options.add(new SelectOption(P[i].getValue(), P[i].getLabel()));
        }
        return options;
    }

 

 

IN your pageBlock method

 

Public Task[] getActivities()

   return [Select id,subject,activitydate,owner.name,pro__Billable_Hrs__c,pro__Rate_Hrs__c,pro__Billable_Amount__c from Task where Status =: strTaskStatus ];
}

 

=======================================================

 

Hope this works for you.

Mahendiran JayavarmaMahendiran Jayavarma

Hi rmeh,

 

Thanks for your help.

 

But I tried to implement custom picklist in my page.

 

But Im getting error for  "Error: Compile Error: Method does not exist or incorrect signature: [String].getDescribe()"

 

 

Please give me solution.

 

Thanks,

Mahendiran

rmehrmeh

Hi,

 

 

Have you exactly done the way i have posted.

As i tested the same in my org and it is working fine.

Could you post what changes have you made to your code?

Mahendiran JayavarmaMahendiran Jayavarma

VF page:

 

<apex:page controller="ActivityController"  >
 <apex:sectionHeader title="Invoice Generate" />
<script type="text/javascript">
 function getCheckedRows(){
alert("hi");
var obj = document.forms[0].elements;

var checkedIds;

for(var i=0;i<obj.lenght;i++){

if(obj.type=='checkbox' and obj.checked='true'){

checkedIds=checkedIds+"~";
alert(checkedIds);

}

}

document.forms[0].ids.value=checkedIds;

}  

</script> <apex:form > <apex:pageBlock > <apex:pageBlockSection title="Search Task" columns="4" > <apex:selectList size="1" id="txtStatus" value="{!strTaskStatus}"> <apex:selectOptions value="{!TaskStatus}"/> </apex:selectList>   <apex:commandButton value="Search" action="{!Search}"/> <input type="hidden" name="ids" value="{!selectedIds}"/> </apex:pageBlockSection> <apex:pageBlockSection title="Search Result" columns="1" > <apex:pageBlockTable value="{!Activities}" var="a" width="750"> <apex:column > <apex:facet name="header">Select</apex:facet> <apex:inputCheckbox value="{!a.Id}" onclick="getCheckedRows();" /> </apex:column> <apex:column value="{!a.subject}" rendered="true"/> <apex:column value="{!a.owner.name}"/> <apex:column value="{!a.Billable_Hrs__c}"/> <apex:column value="{!a.Rate_Hrs__c}"/> <apex:column value="{!a.Billable_Amount__c}"/> </apex:pageBlockTable> </apex:pageBlockSection> <apex:pageBlockButtons > <apex:commandButton value="Generate"/> </apex:pageBlockButtons> </apex:pageBlock></apex:form> </apex:page>

controller:

 

 

public class ActivityController 
{

    public String selectedIds { get; set; }
private List<Task> Taskreport;

public String TaskStatus { get; set; }

    public String strTaskStatus { get; set; }

    public PageReference Search() {
   //  PageReference newpage = new PageReference(System.currentPageReference().getURL());
    //newpage.setRedirect(true);
 //   return newpage;

  // return [Select id,subject,activitydate,owner.name,pro__Billable_Hrs__c,pro__Rate_Hrs__c,pro__Billable_Amount__c from Task where Status =: strTaskStatus ];
  //PageReference p = Page.myPageName
  //return Taskreport;
  return null;
    //    return [Select id, subject,activitydate,owner.name,pro__Billable_Hrs__c,pro__Rate_Hrs__c,pro__Billable_Amount__c from Task where status='Taskstatus'];
    }

Task Task;


 public List<SelectOption> getTaskStatus(){       
 Schema.DescribeFieldResult F = Task.Status.getDescribe();
List<Schema.PicklistEntry> P = F.getPicklistValues();
    List<SelectOption> options = new List<SelectOption>();
      options.add(new SelectOption('','--All--'));
    for(Integer i = 0; i < P.size(); i++){
         options.add(new SelectOption(P[i].getValue(), P[i].getLabel()));
     }
        return options;
    }

public Task getTask() {
      if(Task == null)Task = new Task ();
      
       
      return Task ;
   }

   

    Public Task[] getActivities()
    {
    //return null;
//   Public void  Activites();
//if(Task == null)
//return null;
      
    // else
   //  return Task;
    //  return [Select id, subject,activitydate,owner.name,pro__Billable_Hrs__c,pro__Rate_Hrs__c,pro__Billable_Amount__c from Task];
    Taskreport=[Select id,subject,activitydate,owner.name,pro__Billable_Hrs__c,pro__Rate_Hrs__c,pro__Billable_Amount__c from Task];
    return Taskreport;
    }

//Public Task Activites()
//{
//return [Select id, subject,activitydate,owner.name,pro__Billable_Hrs__c,pro__Rate_Hrs__c,pro__Billable_Amount__c from Task];
//}

     
}

 

 

 

 

 

 

Mahendiran JayavarmaMahendiran Jayavarma

 

now I done my task used by standard piclikst.

 

I can able to filter my records using standard piclikst.

 

 

Thanks,

Mahendiran.