As a part of the Great Code Update of December 2008, I'm reposting this as a much cleaner & neater solution.Say you want to give your users a more intuitive method for filtering SharePoint lists than the toolbar at the top of said list. Doing this is actually a lot easier than I had originally thought.
- While you're viewing the page with the list you want to filter, right-click and select "View Source".
- I'm a tad bit old-school when it comes to editing code so I prefer to work in Notepad++, but using whichever editor is your favorite, you'll need to search through the code for ">[COLUMN NAME TO FILTER]<". Once you've found this bit of text, search up in the code for the first "<TABLE " tag you can find (I intentionally left off the ">" as this tag will have attributes).
- Copy everything between the "<TABLE " and ">/TABLE<" tags.
- Paste this into the "Source Editor..." of a "Content Editor Web Part" anywhere on the page that makes sense to you. This will create a text control much like the one above the column you want to filter. There will be some formatting issues that you probably would want to correct. The easiest way I found to do this was to add the following style attribute to the "<TABLE " tag:
style="border-style:solid;border-width:0px;"
- Here's what the code looks like for one column after I did a bit of cleanup to make it more aesthetically pleasant:
<TABLE
style="width:100%;"
Sortable=""
SortDisable=""
FilterDisable=""
Filterable=""
Name="[COLUMN NAME]"
CtxNum="1"
DisplayName="[COLUMN NAME]"
FieldType="[FIELD TYPE]"
ResultType=""
SortFields=""
height="100%"
cellspacing=1
cellpadding=0
style="border-style:solid;border-width:0px;"
onmouseover="OnMouseOverFilter(this)">
<TR>
<TD width="100%" Class="ms-vb" nowrap>
<A
ID="diidSort[COLUMN NAME]"
onfocus="OnFocusFilter(this)"
TITLE="Filter by [COLUMN NAME]"
HREF="javascript:"
SORTINGFIELDS=""
style="color:black;
font-family:monospace;
font-size:15px">
[COLUMN NAME]
<img src="/_layouts/images/blank.gif"
class="ms-hidden"
border=0
width=1
height=1
alt="Use SHIFT+ENTER to open the menu (new window).">
</A>
<IMG SRC="/_layouts/images/blank.gif" ALT="" BORDER=0>
<IMG SRC="/_layouts/images/filter.gif" BORDER=0 ALT="">
</TD>
<TD style="position:absolute;">
<IMG src="/_layouts/images/blank.gif"
width=13px
style="visibility: hidden"
alt="">
</TD>
</TR>
</TABLE> - It *might* work to copy/paste this code into your CEWP and save the time pawing through the HTML, but you'll have to change every instance of "[COLUMN NAME]" to the ... name of ... the column ... you're using, and "[COLUMN TYPE]" to ... well, you get it. The most likely bug you'll encounter if you try to copy/paste this code is a bad "[COLUMN TYPE]". I don't know what all the options are, but you're probably safe using "Text".


6 comments:
*Arhehem coughGEEK*
I mean, I love you sweety!
Works well! Thank you very much!
Directly copying the template you have there then modifying appropriately worked fine.
Splendid! However I have a query. I noticed that the attribute - 'ctx' decides which list should be filtered. How can I use the same filter on multiple lists. Since this isn't the traditional sharepoint filter webpart, connections won't work.
Hi there,
I'm also very interested in the possibility of being able to filter multiple lists with the one drop down.
Please let us know if this is possible.
Thanks in advance.
Nice post Ben..!!
Here's a post i wrote to demonstrate how we can filter a sharepoint list view using JavaScript.
http://rahul-vartak.blogspot.com/2010/08/sharepoint-2007-filtering-list-view-web.html
Hope this helps..:)
Post a Comment