I know, most of the SharePoint developers are looking for this. As everyone knows we can do partial search on data view web part by passing a parameter to it and by using the expression "contains" we can implement partial search on a field or column. But, when you come to list view web part you can't pass the parameters [There is no support for list view web part like web part parameters] and no way we can implement the partial keyword search. Today I have spent time on it to solve this problem with the help of my colleague Durga and found a wonderful way. This is giving really wonderful result and doing wild card search even on very big document libraries fast. Below are the steps I followed to solve this. [I will post detailed post on it with screen shots and nice explanation soon in this blog.]
- Created an ASPX web part page in a SharePoint site.
- Added two web parts to the page. One is for content editor web part and another is for list view web part of a SharePoint library or list.
- Now, open the page in IE browser and add a text box, button to the content query web part.
- Written simple logic to button click event of the button and reload the page with the below formatted url. The url should be of the format
"you aspx page url?FilterName=FieldName&FilterMultiValue=*valuefromtextbox*".
- In above url, we are using two key value pairs to solve our problem.
- First one is FilterName: which is for in which field of the list view we need to search the value. For example the value may be Title, ID etc…
- Second one is the FilterMultiValue: Which is for what is the value we need to search. i.e. keyword. So, here you can pass multiple values too separated by semi-colon ';'.
- So, example url should like this
- http://mosssite/pages/listviewcustomwildcardsearch.aspx?FilterName=Title&FilterMultiValue=*prav*
- Now the above url will search all the records in the given list view for the keyword "prav". So, wherever it exists in the given field name it will return all records.
Then how it is working?
Generally, If you research on query strings for a list view web part, it expects some query strings to filter and sort. I am SharePoint developer and got to know the two query strings which SharePoint list view web part uses for filtering. FilterName and FilterMultiValue. So, with that my research continued and tried long time with so many operators like %, single quotes, double quotes etc… in the value of the FilterMultiValue. Finally, I tried with * character before and end of the keyword, there I succeeded. Example: *prav* to FilterMultiValue.
- That’s it…. Working simply great.
- With that, You are done implementing the wild card search in a column in list view web part.
Happy by doing SharePoint customization. I know, this will solve so many problems to SharePoint dev’s. Isn’t it? Please let me know if you have any questions, issues and write your valuable feedback and comments.
Will post more descriptive explanation of this post with screenshots soon in this blog. Follow me!!!





10 comments:
Using SharePoint designer you can also promote your ListView web part to a DataView web part, which allows you to choose what parameters to use - including query string parameters.
Here's a fairly complex example from my blog - it talks about the parameters in the lower half of the post.
Your way is quite ingenious, though :)
Thanks for the comment.
But for my requirement, I can't use the data view web part. There are lot of differences to both web parts in rendering and implementation. For my requirement I need to use list view web part and wild card search.
And more over I already mentioned in my blog post like "we can implement it in data view". :)
Really awesome post. Saved so much time.
Hi Praveen,
I have taken the same steps you have provided in your post, but is not working for me.
It is not redirecting the page when i enter some string in the text box and click on the button.
I have even tried editing the url directly in the browser.
In my current example i have list which has a column Analyst and i want to get all the rows which contain "Holloway" in the analyst column.
the url i used is "http://urlofthepage.aspx?FieldName=Analyst&FieldMultiValue=*Holloway*".
Any help.
Hi there,
I have corrected my post as there are minor mistakes in the url. I changed the url correctly and tested. Please try once with new url given and let me know the result. Still if you face any problem then tell me the problem. I will help you out.
And automatically, the page won't refresh when you click submit button. Below is the logic to render the controls and rise the button click event and reload the page with new values. Paste the below as is in the content editor web part.
<script type="text/javascript">
function RedirectUrl()
{
var tb = document.getElementById("tbSearch").value;
if(tb != null)
{
window.location.href="?FilterName=Title&FilterMultiValue=*"+tb+"*";
}
return false;
}
</script>
<input type="text" id="tbSearch" />
<input type="button" id="btnSearch" value="search" onclick="return RedirectUrl();" />
Remember, change the url query string FilterName in the javascript to actual field name. [In your case, it is FilterName=Analyst]
Don't forget.
Hi Praveen,
Thanks for correcting the query string I owe you one, it is working absolutely fine. But I have one other problem when i filter i have say about 60 records and at a time I am displaying on 15 records so when i click on the next page the filter is removed and it is going to the next page of the whole list.
Wonderful, It's a great find by you Praveen. But, I agree with the other guy who said about paging issue. Seems it is loosing the values when you click on page index.
Thanks
Bob.
Hi Praveen,
I have one another problem also.
There are announcement's list on the same page, when i provide a filter string and redirect it the announcement's list shows a error "One or more field types are not installed properly. Go to the list settings page to delete these fields." or some times it shows no announcements inspite the announcements list has some.
HI, i have the same problem, have you find a solution ?
Hi,
To solve the issue that I had (The paging and the one with the Announcement's web part on the same page), I have created different views for the same list and while creating the views we can provide the filters for the list and that's how I solved my problem.
Hope it helps.
Thanks
Blue Diamond.
Post a Comment