Solved

Filter webpart for sharepoint documnet library columns

Posted on 2010-08-19
18
3,198 Views
Last Modified: 2012-05-10
Hii All,
 
 i have one documnet library with multiple columns. let's say i have one column name "Comapny" now i have 250 records in that library. now user wants to search by Company name . i got some out of box web parts but in that web part we need to type whole word. user wants some "Like" methos. so they dont have to type whole word.

If they type A then they can get all records which start with A.

Can i have some third party or and custom or any Out of webpart for that??
0
Comment
Question by:guessdip
  • 10
  • 8
18 Comments
 
LVL 6

Expert Comment

by:Raphilass
ID: 33482768
You can make a filter form using the content editor web part, see below.
 While you can use the form web part to pass values back and forth to filter lists,  they cannot be wild carded to make a partial search. To enable this level of functionaility you have to head off into the realms of SharePoint designer, using the dataview web part and changing the query term to contains...a lot of work for little return.  
By using the content editor webpart and the filter functionaility on the list we can create a similar simple search.   Add a web part page and onto it insert the list webpart you want to filter and a content editor webpart. In the content editor web part edit the source to include your search form and a javascript onclick event for the button to repost the page with a filter based on the value entered into the form. Save and exit edit mode...your done. See the sample content editor script below.

This is the filter value,  this can be retreived from a text box,  by adding or removing the astericks it could be made into a starts with search,  contains or ends with.
The form item could be a text box, or any other form control for that matter.
By using the notation FilterName# and FilterValue# you can create a search with multiple terms, where # is the number of each search term, ie. 1, 2 3 etc.
This is the static name of the field not the display name.
The example below creates a filter based on the entry entered in the input form and fitering the Title field.

  <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>
<table width="100%" cellpadding="5" celspaceing="0" border="0">
<tr>
<td style="text-align:right" width="30%">Please enter a search term and click go to search by client name</td>
<td style="text-align:left" width="175px"><input id="tbSearch" width="150px" type="text" name="T1"></td>
<td style="text-align:left" width="100px"><input type="button" id="btnSearch" value="search" onclick="return RedirectUrl();" />
</td>
<td style="text-align:left" width="100px"><input type="button" id="btnReset" value="reset" onclick="return RedirectUrl();" />
</td>
<td>&nbsp;</td>
</tr>
</table>
By adding multiple inputs and expanding the javascript you can add multiple filters. eg....
<script type="text/javascript">
function RedirectUrl()
{
var tb = document.getElementById("tbSearch").value;
var tb2 = document.getElementById("tbSearch2").value;
if((tb != nul)l && (tb2 != null))
{
window.location.href="?FilterName1=Title&FilterMultiValue1=*"+tb+"*&FilterName2=CompanyName&FilterMultiValue2=*"+tb2+"*";
}

return false;
var tb2 = document.getElementById("tbSearch2").value;}
</script>
<table width="100%" cellpadding="5" celspaceing="0" border="0">
<tr>
<td style="text-align:right" width="30%">Please enter a search term and click search</td>
<td style="text-align:left" width="175px"><input id="tbSearch" width="150px" type="text" name="T1"></td>
<td style="text-align:left" width="100px">Title : <input type="button" id="btnSearch" value="search" onclick="return RedirectUrl();" />
<td style="text-align:left" width="100px">Company Name : <input type="button" id="btnSearch2" value="search" onclick="return RedirectUrl();" />
</td>
<td style="text-align:left" width="100px"><input type="button" id="btnReset" value="reset" onclick="return RedirectUrl();" />
</td>
<td>&nbsp;</td>
</tr>
</table>  
0
 

Author Comment

by:guessdip
ID: 33487372
Hii,
 Thanks for responding, i like your method. i tried for sharepoint list. it works fine. but when i use with documnet library with different columns i am getting odd solution. Also if i have any blank value then when i click reset it display only non blank records.

And i want search using Like statement. means if we type A , we can get result start with A only.


Hope you understand my problem. Let me know if you need more clarification..
0
 
LVL 6

Accepted Solution

by:
Raphilass earned 500 total points
ID: 33488291
Remove the leading * to get only starts with in the line of code...
window.location.href="?FilterName=Title&FilterMultiValue=*"+tb+"*";
so it becomes
window.location.href="?FilterName=Title&FilterMultiValue="+tb+"*";
This should work with a document library,  make sure that the filter name corresponds to the static name of the sharepoint field you want to filter.
="?FilterName=Title  <--- this is the static field name of the sharepoint field, this is the name the field was originally created with, not necessarily the field name it is displaying. A tool like sharepoint manager 2007 can help you find out what this is.
Alternatively you can just apply the filters you want to the view manually fromt he field name dropdown list to see what the resultant URL in the line above should look llike.
 
 
0
 

Author Comment

by:guessdip
ID: 33489410
Hii,

 Thank you so much for helping me. i got it for list and documnet library. but i have two document library. this logic work for only one. i dont know why second one is not working, both have same column. i am trying to solve this.

Do you know whay it is happaning, i also checked the column name.
0
 

Author Comment

by:guessdip
ID: 33489508
Hii,
 i got the problem. Exactly i do have sharepoint 2010. And i am using document set feature. So each documnet has one documnet set ( just like folder with meta data). So it is not filter docuemnt set columns.

I am trying solve this but i dont think so i can solve this.
0
 

Author Comment

by:guessdip
ID: 33502864
Hii Raphilass,

 Definetly i like your solution and i will accept your solution but i have some questions for you. Do you have sharepoint 2010? Can you try to make any Documnet library and can you create Document set content type and try to upload doc??

Exactly i am having issue with filtering when Document Library has Documnet set. I am trying to solve this but no Luck.
0
 
LVL 6

Expert Comment

by:Raphilass
ID: 33504763
Hi There,
Sorry about the late reply, very busy at home and work :). I have sharepoint 2010 setup on a dev machine,  I will try to make it when i finish the job i have to do tomorrow. I haven't really looked at 2010,  so i may not get anywhere, but i will give it a go.
FYI there are lots of other things the content editor web part allows you to do which are pretty cool...Google it :)
I found this site particularly good.
http://blog.pathtosharepoint.com/2008/08/10/the-content-editor-web-part/
Something else i found out recently was how to add webparts into new, view and edit forms which should allow you to implement Javascript to show hide input fields based on other field entries among other things...
http://www.sharepointology.com/setup/add-web-parts-to-dispform-editform-or-newformaspx/
Sorry if you already knew this,  I just love sharing ;)
0
 

Author Comment

by:guessdip
ID: 33505388
Hey Dude,

 Thanks for sharing. I will love it. You can try with documnets sets. and i will give you update. But i liked your approach. it works for sharepont list and simple document library.
0
 
LVL 6

Expert Comment

by:Raphilass
ID: 33509762
Having problems figuring out how create a document set.  Will persevere,  However if this presents a view as a normal list, and you can filter using the field heading on the view, you can filter the list as to how you want to see it and post the URL or at least the querystring part here so i can take a look.
 
Cheers
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 6

Expert Comment

by:Raphilass
ID: 33510175
OK Got this working,  First of all when i created my sample it only adds the Name field not the Title,  you cannot filter the name field using this method.
In my sample i created a document library called document sets, I then added a document set called phils documents to which I added 4 excel spreadsheets. Within the document set / Library i changed the view to display the Title field also. This has to be shown in the view if we are to use it as a filter.
The URLS with a title filter on shown below.
URL of Document Library : http://l057/Document%20Sets/Forms/AllItems.aspx?View={B77F5689-221A-478B-B268-FE323F35B965}&FilterField1=Title&FilterValue1=Phils%20Document%20Set
URL of Document Set : http://l057/Document%20Sets/Forms/Document%20Set/docsethomepage.aspx?ID=2&FolderCTID=0x0120D52000449BCDC1D338BF4E80AEDE9EFC96F412&List=d6467a10-4540-46c6-814c-d087d141517a&RootFolder=%2FDocument%20Sets%2FPhils%20Document%20Set&View={B77F5689-221A-478B-B268-FE323F35B965}&FilterField1=Title&FilterValue1=Mail%20Box%20Sizes
To get the form to work in the Document set we need to maintain the ID part of the querystring,  it tells you which Document Set you are in. Basically the script changes to this....
The new function allows you to rerieve values from the querystring using their key. This is then declared in the original function and added tot he querystring when it is assembled with the URL

<script type="text/javascript">











function getQuerystring(key, default_)

{

  if (default_==null) default_=""; 

  key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");

  var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");

  var qs = regex.exec(window.location.href);

  if(qs == null)

    return default_;

  else

    return qs[1];

}



function RedirectUrl()

{

var tb = document.getElementById("tbSearch").value;

var qs = getQuerystring('ID');

if(tb != null)

{

window.location.href="?FilterName=Title&FilterMultiValue=*"+tb+"*&ID="+qs;

}

return false;

} </script><table width="100%" border="0" cellpadding="5" celspaceing="0"><tbody><tr><td width="30%" style="text-align: right">Please enter a search term and click go to search by client name</td>

<td width="175" style="text-align: left"><input name="T1" width="150" id="tbSearch" type="text"/></td>

<td width="100" style="text-align: left"><input id="btnSearch" onclick="return RedirectUrl();" type="button" value="search"/> </td>

<td width="100" style="text-align: left"><input id="btnReset" onclick="return RedirectUrl();" type="button" value="reset"/> </td>

<td>&#160;</td></tr></tbody></table>

Open in new window

0
 
LVL 6

Expert Comment

by:Raphilass
ID: 33510193
So for further explanation,  lines 7 to 17 gets the value in the querystring based on the key used (In this case ID,  not they are case sensitive)
This function is called in line 22,  where qs is declared as the ID
Finally this is added to the querystring in line 25 (At the end)
One final word,  thanks to http://www.bloggingdeveloper.com/post/JavaScript-QueryString-ParseGet-QueryString-with-Client-Side-JavaScript.aspx for the Function :)
This means that you would have 2 different scripts in the document library, on in the content editor webpart in the main doc library and the one just discussed in the page for the document sets.
0
 

Author Comment

by:guessdip
ID: 33513206
Hii,
 I appreacite your respond. Exactly i tried your code in content editor web part. but when i click save i got url till "ID=". i did not get folder name url. And requiment is : i have 100 document sets and every document set has two documnets. Now i want to filter by Document set Title or and column, But main thing is i dont want to filter by documnet content type column. i want to filter by Document set content type.

And i dont have to display documents , i just have to filter document set..

Hope you understand.. I like your method and i am trying to solve this manually by url. i will let you know if i get solution.

Once agian thank you so much for helping me.. I am learning from you..
0
 

Author Comment

by:guessdip
ID: 33513256
Hii,

 When you filter any Document set title column we can url "http://guessdip/sites/Test/DocumentLibrary/Forms/AllItems.aspx?View={CC63AA08-E5B3-44FC-85D6-13FBD6E0827E}&FilterField1=Title&FilterValue1=ABC"

So i tried to use Filtername and FilterMultiValue instead of FilterField1 but it does not work, it display all records.
0
 
LVL 6

Expert Comment

by:Raphilass
ID: 33514295
Hi My Friend,
I am not going to be able to look at this for a week or so as I am in the middle of moving and won't have interenet etc...
I will get back to it as soon as i can though and hopefully we can get an answer. If you could post the code you put in the web part I might be able to identify why the ID isn't presenting. Using a view will probably differ, i never tried that so will look into it when i get a chance,
 
0
 

Author Comment

by:guessdip
ID: 33514929
Thanks Dude.., Take your time. i will give you update by post.
<script type="text/javascript">











function getQuerystring(key, default_)

{

  if (default_==null) default_=""; 

  key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");

  var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");

  var qs = regex.exec(window.location.href);

  if(qs == null)

    return default_;

  else

    return qs[1];

}



function RedirectUrl()

{

var tb = document.getElementById("tbSearch").value;

var qs = getQuerystring('ID');

if(tb != null)

{

window.location.href="?FilterName=Title&FilterMultiValue=*"+tb+"*&ID="+qs;

}

return false;

} </script><table width="100%" border="0" cellpadding="5" celspaceing="0"><tbody><tr><td width="30%" style="text-align: right">Please enter a search term and click go to search by client name</td>

<td width="175" style="text-align: left"><input name="T1" width="150" id="tbSearch" type="text"/></td>

<td width="100" style="text-align: left"><input id="btnSearch" onclick="return RedirectUrl();" type="button" value="search"/> </td>

<td width="100" style="text-align: left"><input id="btnReset" onclick="return RedirectUrl();" type="button" value="reset"/> </td>

<td>&#160;</td></tr></tbody></table>

Open in new window

0
 

Author Comment

by:guessdip
ID: 33694086
Hii There ,
 
 I tried with documnet set but no luck.  So please let me know if you got something. i am going to close this question. you can email me on guessdip@yahoo.com.
0
 

Author Closing Comment

by:guessdip
ID: 33694096
Thanks dude, I learnt so many things from you.
0
 
LVL 6

Expert Comment

by:Raphilass
ID: 33694767
Hi There,  Sorry i haven't been in touch. Once again busy at work. Thanks for awarding the points.
I am off on holiday soon for a week or so but after that I will try to take another look at this and hopefully help find a resolution.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Summary In SharePoint 2010 it is easy to create custom color themes to jazz up a site. Theme colors can also be created in PowerPoint 2010 with a few clicks. But how do the chosen colors actually look in the SharePoint site? The attached PowerPoint…
We had a requirement to extract data from a SharePoint 2010 Customer List into a CSV file and then place the CSV file into a directory on the network so that the file could be consumed by an AS400 system. I will share in Part 1 how to Extract the Da…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now