Thursday, May 17, 2007

Creating an advanced search on a list

If you ever wanted to have an advanced property search on a SharePoint list – your worries are now over.

Almost all SharePoint lists views supports having a filter-combo box above them. Only you have to show the toolbarin order to use it and it hides the filter boxes by default.

here is a little javascript code snippet that will force the list web part always show the filter combo boxes and thus providing property-based search on your list.

All you have to do is add a content editor web part to your page and add this javascript to its source editor:

function NewSubmitFormPost(url)
if( url.indexOf("?") > 0 )
url += "&";
url += "?";
url += "Filter=1";

var OrgSubmitFormPost = SubmitFormPost;
SubmitFormPost = NewSubmitFormPost;

if( window.location.href.indexOf("Filter=1") < 1 )
window.location.href = window.location.href + "?Filter=1";


This little code bit sure saved me some long development hours...


evshell18 said...

This didn't work and now I can't edit the page anymore, because when I go to Site Actions -> Edit Page, it just posts back and won't show the edit pane.

Anonymous said...

I had the same problem and then you have to delete the library to get rid of it.

Shai Petel said...

You can get rid of the change if it is not working for you simply by deleting the view.

First go to create a new view, select the one that you want to delete as the template, mark it as default if it was the default and confirm to create it.
once done - just delete the non-working view.

Another way is to use SharePoint Designer but it take more effort and time.

good luck!

Anonymous said...

Hi Shai,

I too faced the same issue as the users above. I tried the workaround you suggested but even that didnt help. I had to delete the library.

Shai Petel said...

That is strange and unfortunate,
perhaps email me to shai at kwizcom dot com and i could have a look-see?