You need to sign in to do that
Don't have an account?
Chicho
Lookup - Picklist field to filter data in a Visualforce page
Can I filter the data displayed in a HTML table in a visualforce page by using a lookup field or a picklist field? My idea is to embedded a lookup field or a picklist field in the Visualforce page so the data displayed would be filter by the value previously selected.
Yes you can filter records based on a picklist or a lookup field. Your code would be something like
Controller
Well replace "CustomObject__c" , "LookupField__c" with proper api name of your object and this code should work fine(can have syntax errors :P )
All Answers
Yes you can filter records based on a picklist or a lookup field. Your code would be something like
Controller
Well replace "CustomObject__c" , "LookupField__c" with proper api name of your object and this code should work fine(can have syntax errors :P )
Thanks a lot!! I wrote the code and worked :) I'm trying now to add a second filter which values would depend on those previoudly selected in the first filter. How can I do this?
Hi Avi, I tried your code and getting below error. could you please help me to fix it. Custom object name: Sales_S__C, picklist field: Stage__c
Error: Unknown method 'MyFilter.filter()'
VF Page:
<apex:page controller="MyFilter">
<apex:form>
<apex:inputField value="{!YourObjReference.Stage__c}"/>
<apex:pageblock>
<apex:commandButton action="{!filter}" value="FILTER" />
<apex:pageblockTable value="{!yourObjList}" var="obj">
<apex:column value="{!obj.name}"/>
</apex:pageblockTable>
</apex:pageblock>
</apex:form>
</apex:page>
Controller:
public class MyFilter{
public MyFilter(){
YourObjReference = new Sales_C__c();
}
public Sales_C__c YourObjReference{get;set;}
public List<Sales_C__c> yourObjList{get;set;}
public void filterRecords(){
yourObjList = new List<Sales_C__c>();
yourObjList = [SELECT Name FROM Sales_C__c WHERE Stage__c=:YourObjReference.Stage__c];
}
}
I found the answer. Thanks anyways. It really helps me.
How did you fix Error: Unknown method 'MyFilter.filter()' ?
I am getting same error please suggest.
Thanks
Sudhir
could you please share the myfilter.filter solution with us as well? :) thanks
is to change Avidev9's Visualforce Page Line 4 from:
<apex:commandButton action="{!filter}" value="FILTER" />
to
<apex:commandButton action="{!filterRecords}" value="FILTER" />