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
Anuj Joshi 42Anuj Joshi 42 

Filter records in table based on input

Hi All,

I have a requirement that in a visualforce page i need to display case records where owner is the current logged in user. It should come in a table. Also there should be a search box on the top of table. When the user puts the case subject or number on the box and clicks on search button the table should refresh and show that particular record. When the user loads the page initially it should show user case records in table with pagination. After search button is clicked table should get refereshed.
Kindly provide me the example.

Thanks,
Anuj
Pradeep SinghPradeep Singh
Hi, Refer below code:-

----Page---
<apex:page controller="caserecords">
<apex:form>
    <apex:pageBlock>
        <apex:inputText label="Search" value="{!searchVar}"/>
        <apex:commandButton value="Search" action="{!search}" reRender="Casetable"/>
        <apex:pageBlockTable value="{!caseList}" var="case" id="Casetable">
            <apex:column value="{!case.CaseNumber}"/>
            <apex:column value="{!case.Subject}"/>
            <apex:column value="{!case.Reason}"/>
        </apex:pageBlockTable>
    </apex:pageBlock>
</apex:form>
</apex:page>

------class-----
public class caserecords{
    
    public List<case> caseList{get;set;}
    public string searchVar{get;set;}
    string userid ;
    public caserecords(){
        userid= userInfo.getUserId() ;
        caseList = [Select id,Subject,Reason,CaseNumber FROM Case where OwnerId =: userid];
    }    
    
    public void search(){
        if(searchVar != Null){
            caseList = [Select id,Subject,Reason,CaseNumber FROM Case where OwnerId =: userid AND (CaseNumber=:searchVar OR Subject=:searchVar)];
        }
    }
}



If this solves your problem,please mark it as solved.
Anuj Joshi 42Anuj Joshi 42
Hi Pradeep,

Its not working. I am able to achieve case functionality but my requirement is when i open the page i should get records in table owned by me. If the user has many records he may put subject the search box and then the table is refreshed. Initially table should contain all the records owned by the user.
Pradeep SinghPradeep Singh
Anuj,
What errors are you getting..?? 
Anuj Joshi 42Anuj Joshi 42
Hi Pradeep,

Apologies. I am not getting any errors. The thing is its not showing the records initially. I have removed where condition. Requirement is

Step 1: When page is opend all records owned by user are seen by default without clicking any button.

User-added image

Step2: if the user searches for a particular case number and clicks on search button table should refresh and that records should be displayed.

User-added image

When page is loaded the records are not coming in the table.

Thanks,
Anuj
Pradeep SinghPradeep Singh
Anuj,

In your second image, the record is present and while loading means initially or refreshing the page you can see in 1st image, all records are there.