Search records :                                                                                 
         public class Attachmentsviewcontroller{          public List att{get;set;}     Public string recnamesearch{get;set;}         public Attachmentsviewcontroller()         {             att=[Select a.Id , a.a.Name ,a.BodyLength From Attachment a];         } } Above the code is an Global Search if you want to only name based search you have add id on name column. Thanks, Raghavendra Reddy.D  ", "upvoteCount": 0, "url": "https://trailhead.salesforce.com/trailblazer-community/feed/0D54V00007T4CrLSAV", "datePublished": "2016-12-07T05:21:39.000Z", "author": { "@type": "Person", "name": "SFDC tution", "url": "https://trailblazers.salesforce.com/profileView?u=0053A00000DqdEiQAJ", "affiliation": { "@type": "Organization", "name": "INFO" } } }, "suggestedAnswer": [ { "@type": "Answer", "text": "Thanks Ragava reddy. this Helped a lot. ", "upvoteCount": 0, "url": "https://trailhead.salesforce.com/trailblazer-community/feed/0D54V00007T4CrLSAV", "datePublished": "2016-12-07T15:19:41.000Z", "author": { "@type": "Person", "name": "sarvendra aeturu", "url": "https://trailblazers.salesforce.com/profileView?u=0053A00000CYNfWQAX", "affiliation": { "@type": "Organization", "name": "developer" } } } ] } }
Skip to main content
sarvendra aeturu (developer) a posé une question dans #Visualforce
i have a requirement to display custom object attachments on a visualforce page with a search functioanlity(able to search by the document name) i can able to develope the visualforce page to display the attachments in a visualforce page. please help me in writing the search functionality.

below is the code 

VF page

<apex:page controller="KnowledgeBaseAttachment" showheader="false" >

<apex:form >

<apex:pageBlock >

<apex:pageBlockSection columns="2">

<apex:repeat value="{!listAttachment}" var="att">

<apex:pageBlockSectionItem >

<apex:outputLink value="{!URLFOR($Action.Attachment.Download, att.id)}" target="_blank">{!att.name}

</apex:outputLink>

</apex:pageBlockSectionItem>

</apex:repeat>

</apex:pageBlockSection>

</apex:pageBlock>

</apex:form>

</apex:page>

controller code 

public class KnowledgeBaseAttachment {

    public List<Attachment> listAttachment {get; set;}

    public KnowledgeBaseAttachment() {

        listAttachment = new List<Attachment>();

        List<aeturu__Knowlegde_Base__c> lstKnowledgeBase = [Select Id, (Select Id, Name from Attachments)

                                                            from aeturu__Knowlegde_Base__c];

        for (aeturu__Knowlegde_Base__c obj : lstKnowledgeBase) {

            listAttachment.addAll(obj.Attachments);

        }

    }

}

any help is appriciated

thanks 

sarvam
2 réponses
  1. 7 déc. 2016, 05:21
    Hi Sravam,

    Can u please check with below code it will works for you,

    <apex:page controller="Attachmentsviewcontroller" showHeader="false">

        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

                    <script>

                        $.noConflict();

                        jQuery(document).ready(function() {

                            jQuery.extend(jQuery.expr[":"], {

                                "containsIN": function(elem, i, match, array) {

                                    return (elem.textContent || elem.innerText || "").toLowerCase().indexOf((match[3] || "").toLowerCase()) >= 0;

                                }

                            });

                            jQuery(document).on("keyup", ".searchbynameautsearch", function() {

                                jQuery('.list tbody tr').each(function() {

                                    jQuery(this).css("display", "table-row");

                                })

                                var searchterm = jQuery(this).val();

                                if (searchterm.length > 0) {

                                    var lmatch = jQuery('.list tbody tr').text();

                                    var match = jQuery('.list tbody tr:containsIN("' + searchterm + '")');

                                    var nomatch = jQuery('.list tbody tr:not(:containsIN("' + searchterm + '"))');

                                    match.addClass('selected');

                                    nomatch.css("display", "none");

                                } else {

                                    jQuery('.list tbody tr').css("display", "");

                                    jQuery('.list tbody tr').removeClass('selected');

                                }

                            });

                        });

                    </script>

                    

        <apex:form ><br/><br/>

            Search records :<apex:inputText value="{!recnamesearch}" styleClass="searchbynameautsearch serchfld" style="padding-left:5px;" />

            <apex:pageblock id="account" title="Attachments" >

                <apex:pageblockTable value="{!att}" var="a">

                    <apex:column value="{!a.Name}" headerValue="File Name"/>

                    <apex:column value="{!a.BodyLength }" headerValue="Size"/>

                </apex:pageblockTable>

            </apex:pageblock>

        

        </apex:form>

            

    </apex:page>

    public class Attachmentsviewcontroller{

        

        public List<Attachment> att{get;set;}

        Public string recnamesearch{get;set;}

            public Attachmentsviewcontroller()

            {

                att=[Select a.Id,a.a.Name,a.BodyLength From Attachment a];

            }

    }

    Above the code is an Global Search if you want to only name based search you have add id on name column.

    Thanks,

    Raghavendra Reddy.D

     
0/9000