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
PeachTreePeachTree 

Display search results in a popup window in visualforce

I have created an input field in visualforce which displays some search results when a button (named search) is clicked. I am able to write the apex code to display the results. However, I want to display the search results in a new pop-up window . I have read this post and was able to create a pop up window. 

http://www.salesforcegeneral.com/salesforce-modal-dialog-box/

 

This is my visualforce code which produces search results. 

 

<apex:page sidebar="false" showHeader="false" standardController="Account" extensions="SearchSuiteNumber">
<p>Enter the account number to search</p>
<apex:form >
<apex:pageBlock mode="edit" id="block">
<apex:pageBlockSection >
<apex:pageBlockSectionItem >
<apex:panelGroup >
<apex:inputText id="searchText" value="{!searchText}"/>
<apex:commandButton value="Search" action="{!search}" rerender="block" status="status"/>
</apex:panelGroup>
</apex:pageBlockSectionItem>
</apex:pageBlockSection><br/>

<apex:actionStatus id="status" startText="Searching... please wait..."/>
<apex:pageBlockSection title="Search Results" id="resultsBlock" columns="1">
<apex:pageBlockTable value="{!searchResults}" var="item" rendered="{!NOT(ISNULL(searchResults))}">
<apex:column value="{!item.Name}" headerValue="Customer" width="30"/>
<apex:column value="{!item.Acc_Num__c}" headerValue="Account Number" width="35"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

 

Apex Class:

 

public with sharing class SearchAccountNumber {

private ApexPages.StandardController controller {get; set;}
public List<Account> searchResults {get;set;}
public string searchText {get;set;}

public SearchAccountNumber(ApexPages.StandardController controller) { }

// fired when the search button is clicked
public PageReference search()
{
String qry = 'select id, Name, Acc_Num__c from Account WHERE Acc_Num__c LIKE \'%'+searchText+'%\'';
searchResults = Database.query(qry);
return null;
}
}

 

Please help as this issue is urgent for me. 

 

Thanks a lot.

LithiumsLithiums

Hi,

 

i did it a little different using jquery, hope this serves your purpose. You might want to download the jquery and save it static resource if you are going this route.

 

<apex:page sidebar="false" showHeader="false" standardController="Account" extensions="SearchAccountNumber">


<apex:includeScript value="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" />
<apex:includeScript value="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.1/jquery-ui.min.js" />
<apex:stylesheet value="//ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery.ui.theme.css"/>
<apex:stylesheet value="//ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery.ui.base.css"/>

<script type="text/javascript">
$(document).ready(function() {
$('#dialog').hide();
$('#dialog').dialog({
title: "Choose Activity ",
autoOpen: false,
resizable: false,
width: 600
});
});

function showDialog(){
$("#dialog").dialog('open')

}
</script>

<p>Enter the account number to search</p>
<apex:form >
<apex:pageBlock mode="edit" id="block">
<apex:pageBlockSection >
<apex:pageBlockSectionItem >
<apex:panelGroup >
<apex:inputText id="searchText" value="{!searchText}"/>
<apex:commandButton value="Search" action="{!search}" status="status" onclick="showDialog()" reRender="re"/>
</apex:panelGroup>
</apex:pageBlockSectionItem>
</apex:pageBlockSection><br/>
</apex:pageBlock>

<body>
<div id="dialog" >
<apex:pageBlock id="re">
<apex:pageBlockTable value="{!searchResults}" var="item" rendered="{!NOT(ISNULL(searchResults))}">
<apex:column value="{!item.Name}" headerValue="Customer" width="30"/>
<apex:column value="{!item.AccountNumber}" headerValue="Account Number" width="35"/>
</apex:pageBlockTable>
</apex:pageBlock>
</div>
</body>
</apex:form>
</apex:page>

 

public with sharing class SearchAccountNumber {

private ApexPages.StandardController controller {get; set;}
public List<Account> searchResults {get;set;}
public string searchText {get;set;}

public SearchAccountNumber(ApexPages.StandardController controller) { }

// fired when the search button is clicked
public PageReference search()
{
String qry = 'select id, Name, AccountNumber from Account WHERE AccountNumber LIKE \'%'+searchText+'%\'';
searchResults = Database.query(qry);
return null;
}
}