Tuesday, August 31, 2010

Set default search to list scope in SharePoint

Hi All,

We know built in search functionality in SharePoint. When configured properly, you can search from entire site just anything and search will categorize the results for you.

However a simple scenario came to me last week. When you are on any list AllItems.aspx page and if you have observed, by default search scope on top right is set to “This site: {site name}”.

This List: {list name} by default instead of This Site: {site name} so that they directly can put in words and search from that list.

So go ahead and open view source of the page, search for This List: {list name} and take out its ID. It should be ending with SBScopesDDL.

And add content editor web part on AllItems.aspx and paste the following code. Do not forget to reference correct jQuery js location.

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>

<script type="text/javascript" >

$(document).ready(function() {
//Below function makes sure that if the status is not suspended in edit mode, it disables the reason text //area
var text = $("select[title$='Search Scope'] :selected").text();

$("#ctl00_PlaceHolderSearchArea_ctl01_SBScopesDDL").val("This List: YOUR LIST NAME ");

});

</script>
</script>


And you are good to go. Observe the top search box, you will find by default This List : {list name} selected.

1 comment:

Anonymous said...

Sweet. Exactly what I was looking for - that easy. Thanks for sharing.




Share your SharePoint Experiences with us...
As good as the SharePointKings is, we want to make it even better. One of our most valuable sources of input for our Blog Posts comes from ever enthusiastic Visitors/Readers. We welcome every Visitor/Reader to contribute their experiences with SharePoint. It may be in the form of a code stub, snippet, any tips and trick or any crazy thing you have tried with SharePoint.
Send your Articles to sharepointkings@gmail.com with your Profile Summary. We will Post them. The idea is to act as a bridge between you Readers!!!

If anyone would like to have their advertisement posted on this blog, please send us the requirement details to sharepointkings@gmail.com