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
Lukasz PiziakLukasz Piziak 

PageBlockTable - Populating filtered records?

Hi All,

Is there a way of populating a list of records in the PageBlockTable Section based on a filter criteria? Basically I have a records with different production status value. Let say I have 20 records with status = open and 45 records with status value = complete,
I woudl like  to dispaly records with satus open only. 

Thank you for any suggestions and help.

Below is my code for my table:

<apex:page standardController="SCMC__Production_Order__c" sidebar="false" showheader="false" recordSetVar="SCMC__Production_Order__c">

<apex:form >
<apex:pageBlock rendered="True" title="Production Orders">
<apex:pageBlockSection title="Production Orders to Fill">
<apex:pageBlockTable value="{!SCMC__Production_Order__c}" style="width:1220px" var="item">
<apex:column style="width:100px" headerValue="Production Order No." value="{!item.name}" />
<apex:column style="width:100px" value="{!item.Sales_Order_No__c}"/>
<apex:column style="width:100px" value="{!item.Customer__c}" headerValue="Customer Name"/>
<apex:column style="width:200px" value="{!item.Assembly_Name__c}" headerValue="Hose Description"/>
<apex:column style="width:150px" value="{!item.SCMC__Start_Date__c}" headerValue="Production Start Date"/>
<apex:column style="width:150px" value="{!item.SCMC__Planned_Completion_Date__c}" headerValue="Planned Completion Date"/>
<apex:column style="width:150px" value="{!item.SCMC__Production_Status__c}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
 
Best Answer chosen by Lukasz Piziak
William TranWilliam Tran
If you use the rendered attribute, you are literally hiding the rows not really filtering.  You may see side effect like missing column names, empty rows displaying, etc.

You are better off creating an extension class like "TestExtension", use SOQL to query you object with the filter applies in the where clause and passing the filterd list of SCMC__Production_Order__c back to be render in your visual force page.

change your Page in 2 places see underline/bold.
<apex:page standardController="SCMC__Production_Order__c" sidebar="false" showheader="false" recordSetVar="SCMC__Production_Order__c" extensions = "TestExtension">

<apex:form >
<apex:pageBlock rendered="True" title="Production Orders">
<apex:pageBlockSection title="Production Orders to Fill">
<apex:pageBlockTable value="{!objlist}" style="width:1220px" var="item">

Add class
public class TestExtension {
    public List<SCMC__Production_Order__c> objlist{get;set;}
    public TestExtension(ApexPages.StandardSetController controller) {
    objlist = [SELECT Name, Sales_Order_No__c, Customer__c, Assembly_Name__c, SCMC__Start_Date__c, SCMC__Planned_Completion_Date__c, SCMC__Production_Status__c
FROM SCMC__Production_Order__c Where SCMC__Production_Status__c = 'open'];
    }
}
Save and run.

Thx.

All Answers

Shashikant SharmaShashikant Sharma
There are two solutions for you:

1. Use rendered="{!IF(item.Status__c = 'Open', true, false)}" in each of your column like

<apex:column rendered="{!IF(item.Status__c = 'Open', true, false)}" style="width:100px" headerValue="Production Order No." value="{!item.name}" />

2. If it does not break any other logic in comtroller then filter the records in Apex itself when you are fetching them

Thanks
​Shashikant
 
Lukasz PiziakLukasz Piziak
Hi Shashikant,

Thank you for your quick reply. I have used your first option and I think This will not work for me as the records with other status are still displayed.
Could you please explain to me of how I can filter the Apex itself?
 
Lukasz PiziakLukasz Piziak

Shashikant,

Please see below print screen before I have used render IF code
User-added image

Here is after
User-added image

 
Prosenjit Sarkar 7Prosenjit Sarkar 7
Hi Lukasz,
You need to use rerendered attribute in each column you declared. Here is the code,
 
<apex:page standardController="SCMC__Production_Order__c" sidebar="false" showheader="false" recordSetVar="SCMC__Production_Order__c">
	<apex:form >
	<apex:pageBlock rendered="True" title="Production Orders">
		<apex:pageBlockSection title="Production Orders to Fill">
			<apex:pageBlockTable value="{!SCMC__Production_Order__c}" style="width:1220px" var="item">
				<apex:column style="width:100px" headerValue="Production Order No." value="{!item.name}" rendered="{!item.SCMC__Production_Status__c == 'Open'}"/>
				<apex:column style="width:100px" value="{!item.Sales_Order_No__c}" rendered="{!item.SCMC__Production_Status__c == 'Open'}"/>
				<apex:column style="width:100px" value="{!item.Customer__c}" headerValue="Customer Name" rendered="{!item.SCMC__Production_Status__c == 'Open'}"/>
				<apex:column style="width:200px" value="{!item.Assembly_Name__c}" headerValue="Hose Description" rendered="{!item.SCMC__Production_Status__c == 'Open'}"/>
				<apex:column style="width:150px" value="{!item.SCMC__Start_Date__c}" headerValue="Production Start Date" rendered="{!item.SCMC__Production_Status__c == 'Open'}"/>
				<apex:column style="width:150px" value="{!item.SCMC__Planned_Completion_Date__c}" headerValue="Planned Completion Date" rendered="{!item.SCMC__Production_Status__c == 'Open'}"/>
				<apex:column style="width:150px" value="{!item.SCMC__Production_Status__c}" rendered="{!item.SCMC__Production_Status__c == 'Open'}"/>
			</apex:pageBlockTable>
		</apex:pageBlockSection>
	</apex:pageBlock>
</apex:form>
</apex:page>
Thanks
Prosenjit
 
William TranWilliam Tran
If you use the rendered attribute, you are literally hiding the rows not really filtering.  You may see side effect like missing column names, empty rows displaying, etc.

You are better off creating an extension class like "TestExtension", use SOQL to query you object with the filter applies in the where clause and passing the filterd list of SCMC__Production_Order__c back to be render in your visual force page.

change your Page in 2 places see underline/bold.
<apex:page standardController="SCMC__Production_Order__c" sidebar="false" showheader="false" recordSetVar="SCMC__Production_Order__c" extensions = "TestExtension">

<apex:form >
<apex:pageBlock rendered="True" title="Production Orders">
<apex:pageBlockSection title="Production Orders to Fill">
<apex:pageBlockTable value="{!objlist}" style="width:1220px" var="item">

Add class
public class TestExtension {
    public List<SCMC__Production_Order__c> objlist{get;set;}
    public TestExtension(ApexPages.StandardSetController controller) {
    objlist = [SELECT Name, Sales_Order_No__c, Customer__c, Assembly_Name__c, SCMC__Start_Date__c, SCMC__Planned_Completion_Date__c, SCMC__Production_Status__c
FROM SCMC__Production_Order__c Where SCMC__Production_Status__c = 'open'];
    }
}
Save and run.

Thx.
This was selected as the best answer
William TranWilliam Tran
I guess formatting does not work in code block :-)  

so basicall add this: extensions = "TestExtension"
and change to this: value="{!objlist}"

thx
Lukasz PiziakLukasz Piziak
Hi William,
Thank you for your help. This is exactly what I want!!!
Is working for me now and it is filtering based on Class you have provided. 

Could you please advise if I can use more than one extension in one VP? In my case I have a page with 2 page BlockTables.
One is displaying all records with 'Open' status and second table I wish to display all records with 'complete' status.

Please find below code a full version of the code I have used for this page:

<apex:page standardController="SCMC__Production_Order__c" sidebar="false" showheader="true" recordSetVar="SCMC__Production_Order__c" extensions="TestExtension">

<apex:form >
<apex:pageBlock rendered="True" title="Production Orders">
<apex:pageBlockSection title="Production Orders to Fill">
<apex:pageBlockTable value="{!objlist}" style="width:1220px" var="item">
<apex:column style="width:100px" headerValue="Production Order No." value="{!item.name}" />
<apex:column style="width:100px" value="{!item.Sales_Order_No__c}"/>
<apex:column style="width:100px" value="{!item.Customer__c}" headerValue="Customer Name"/>
<apex:column style="width:200px" value="{!item.Assembly_Name__c}" headerValue="Hose Description"/>
<apex:column style="width:150px" value="{!item.SCMC__Start_Date__c}" headerValue="Production Start Date"/>
<apex:column style="width:150px" value="{!item.SCMC__Planned_Completion_Date__c}" headerValue="Planned Completion Date"/>
<apex:column style="width:150px" value="{!item.SCMC__Production_Status__c}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>

<apex:pageBlockSection title="Production Order in Progress">
<apex:pageBlockTable value="{!SCMC__Production_Order__c}" style="width:1220px" var="item">
<apex:column style="width:100px" value="{!item.name}" headerValue="Production Order No."/>
<apex:column style="width:100px" value="{!item.Sales_Order_No__c}"/>
<apex:column style="width:100px" value="{!item.Customer__c}" headerValue="Customer Name"/>
<apex:column style="width:200px" value="{!item.Assembly_Name__c}" headerValue="Hose Description"/>
<apex:column style="width:150px" value="{!item.Hose_Assembly_By__c}" headerValue="Technician"/>
<apex:column style="width:150px" value="{!item.SCMC__Planned_Completion_Date__c}" headerValue="Planned Completion Date"/>
</apex:pageBlockTable>

</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
 
Lukasz PiziakLukasz Piziak
Thank you guys for all help. 
Now after adding another extension class to my VP my tables displaying records based on two dfferent filter settings.
Below is full code and classess.

Visual Page:
<apex:page standardController="SCMC__Production_Order__c" sidebar="false" showheader="true" recordSetVar="SCMC__Production_Order__c" extensions="TestExtension,TestExtension2">

<apex:form >
<apex:pageBlock rendered="True" title="Production Orders">
<apex:pageBlockSection title="Production Orders to Fill">
<apex:pageBlockTable value="{!objlist}" style="width:1220px" var="item">
<apex:column style="width:100px" headerValue="Production Order No." value="{!item.name}" />
<apex:column style="width:100px" value="{!item.Sales_Order_No__c}"/>
<apex:column style="width:100px" value="{!item.Customer__c}" headerValue="Customer Name"/>
<apex:column style="width:200px" value="{!item.Assembly_Name__c}" headerValue="Hose Description"/>
<apex:column style="width:150px" value="{!item.SCMC__Start_Date__c}" headerValue="Production Start Date"/>
<apex:column style="width:150px" value="{!item.SCMC__Planned_Completion_Date__c}" headerValue="Planned Completion Date"/>
<apex:column style="width:150px" value="{!item.SCMC__Production_Status__c}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>

<apex:pageBlockSection title="Production Order in Progress">
<apex:pageBlockTable value="{!objlist2}" style="width:1220px" var="item">
<apex:column style="width:100px" value="{!item.name}" headerValue="Production Order No."/>
<apex:column style="width:100px" value="{!item.Sales_Order_No__c}"/>
<apex:column style="width:100px" value="{!item.Customer__c}" headerValue="Customer Name"/>
<apex:column style="width:200px" value="{!item.Assembly_Name__c}" headerValue="Hose Description"/>
<apex:column style="width:150px" value="{!item.Hose_Assembly_By__c}" headerValue="Technician"/>
<apex:column style="width:150px" value="{!item.SCMC__Planned_Completion_Date__c}" headerValue="Planned Completion Date"/>
<apex:column style="width:150px" value="{!item.SCMC__Production_Status__c}"/>
</apex:pageBlockTable>

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

TestExtension Class:
public class TestExtension {
    public List<SCMC__Production_Order__c> objlist{get;set;}
    public TestExtension(ApexPages.StandardSetController controller) {
    objlist = [SELECT Name, Sales_Order_No__c, Customer__c, Assembly_Name__c, SCMC__Start_Date__c, SCMC__Planned_Completion_Date__c, SCMC__Production_Status__c
FROM SCMC__Production_Order__c Where SCMC__Production_Status__c = 'Pending Pulling All Items'];
    }
}

TestExtension2 Class:
public class TestExtension2 {
    public List<SCMC__Production_Order__c> objlist2{get;set;}
    public TestExtension2(ApexPages.StandardSetController controller) {
    objlist2 = [SELECT Name, Sales_Order_No__c, Customer__c, Assembly_Name__c,Hose_Assembly_By__c, SCMC__Planned_Completion_Date__c, SCMC__Production_Status__c
FROM SCMC__Production_Order__c Where SCMC__Production_Status__c = 'Pulled All Items'];
    }
}