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
RAJU_DEEPRAJU_DEEP 

Show different results in one pageBlockTable.

Hello,

           here i am creating a visualforce page which is performing two task:

1. Display the search records in the pageBlockTable.

2. Display the whole recordsin the pageBlockTable.

           there are two different pageBlockTable to do this task, but i want this task to be rendered in the same pageBlockTable i.e by default the whole records are shown but as i click to the search button the search records should be shown in the same pageBlockTable instead of showing it in seperate table, the code which i have tried is given below. Is there any way to do this. Any idea related this will be greatly appreciated...

 

Visualforce page code:

 

 

<apex:page sidebar="false" showHeader="false" controller="ShippingApps">
<apex:form>
<center>
<h1 style="font-size:40px; font-family:Comic Sans MS; font-weight:bolder">Shipping Invoice</h1><br/><br/>
<apex:outputText value="Shipping Invoice Name :"/><apex:inputText value="{!shipName}"/><br/><br/>
<apex:commandButton value="Search" action="{!doSearch}" rerender="block1" status="status"/>
</center><br/><br/>
<apex:pageBlock mode="edit" id="block1">
<apex:actionStatus id="status" startText="requesting..."/>
<apex:pageBlockSection title="Results" id="results" columns="1">
<apex:pageBlockTable value="{!results}" var="l" rendered="{!NOT(ISNULL(results))}">
<apex:column value="{!l.name}"/>
<apex:column value="{!l.Subtotal__c}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>

<apex:pageBlock title="Shipping Invoice" id="block">
<apex:pageBlockTable value="{!invoice}" var="s">
<apex:column value="{!s.name}"/>
<apex:column value="{!s.Subtotal__c}"/>
</apex:pageBlockTable>
</apex:pageBlock>

</apex:form>
</apex:page>

 

 

The ShippingApps Controller code:

 

 

public class ShippingApps{
    public String shipName{get; set;}
    
    public List<Shipping_Invoice__c> getInvoice() {
        return [select id, name, Subtotal__c, GrandTotal__c, Shipping__c, ShippingDiscount__c, Tax__c, TotalWeight__c from Shipping_Invoice__c ];
    }
    
    List<Shipping_Invoice__c> results;
    public String getShipName() {
        return shipName;
    }
    public void setShipName(String s) {
        shipName = s;
    }
    public List<Shipping_Invoice__c> getResults() {
        return results;
    }
    public PageReference doSearch() {
        results = (List<Shipping_Invoice__c>)[FIND :shipName RETURNING Shipping_Invoice__c(name, Subtotal__c, GrandTotal__c, Shipping__c, ShippingDiscount__c, Tax__c, TotalWeight__c)][0];
        return null;
    }
}

 

Thanks...

 

Imran MohammedImran Mohammed

Add a constructor that calls the doSearch() function.

public ShippingApps()

{

doSesarch();

}

In doSearch function, construct the query as below,

 

String query = "select id, name, Subtotal__c, GrandTotal__c, Shipping__c, ShippingDiscount__c, Tax__c, TotalWeight__c from Shipping_Invoice__c ";

String percentile = '%';

if(shipName.length() > 0)

{

    query += " where name = :shipName ";

}

else

{

   query += " where name = :percentile ";

}

 

results = Database.query(query);

 

In Visualforce page, remove the second pageblock.

 

If you have any queries pleasde let me know.

 

Regards,

Imran