Solution for multiple filters… (Javascript/Forms Solution)

August 21st, 2007 by chadclarke

This was a post on Discussions in microsoft.public.sharepoint.development_and_programming.  This may not be the most complete solution, but you will not have to use custom web parts to implement.  Ok so, we want three different columns we can filter on for a basic list web part that can only connect to one web part at a time…  Well, as long as we only want one of the columns to search on at a time….  We can do a little slap and tickle(Beer Fest, good movie).  So the solution here would be to use a forms web part to put a drop down on the page, then place three identical list web parts on the page and three text filter web parts.  Set up the appropriate connections between each set of webparts.  Write some javascript code to hide/show the appropriate web parts based on the dropdown selection, and there you have the ability to search on multiple columns from one list using the default sharepoint filtering capabilities.

So this script below should get you on your way.  I developed formatList in order to place a tab type menu inside of a sharepoint page, but it should work for this application as well.  Place this text inside of a form web part for the dropdown menu.  You can minimize all the filtered web parts to start with.  Good luck and god bless your journeys in the World of SharePoint!

<div onkeydown="BLOCKED SCRIPTif (event.keyCode == 13) _SFSUBMIT_">

<select name=searchType onChange="show(this.selectedValue)">
<option value='column1'>Column1</option>
<option value="column2">Column2</option>
<option value="column3">Column3</option>
<option value="column4">Column4</option>
</select>

</div>

<script>
function removeTitle(listName){
 var tds = document.getElementsByTagName('td');
 for(var j = 0; j < tds.length; j++){
  if(tds[j].title.indexOf(listName) != -1){
   var minimizedWebPart = tds[j].parentNode;
   minimizedWebPart.style.display = "none";
   break;
  }
 }
}
//Use this if publishing is enabled on this site, otherwise just check the hyperlinks for "exit edit mode" link.
var EditMode = false;
var publishingMenu = document.getElementById("ctl00_SPNavigation_ctl01_toggleContainerColorBar");
if(publishingMenu)
 EditMode = true;

//if edit mode clear titles
if(EditMode == false){
  removeTitle('WebPart1');
  removeTitle('WebPart2');
  removeTitle('WebPart3');
}

function show(webpartTitle){
  formatList(webpartTitle, 300, true, true)
   //script to hide other windows…
}

function formatList(listName, height, scrollable, display){
 var tds = document.getElementsByTagName('td');
 var webpartZone;
 var webpartRow;
 for(var j = 0; j < tds.length; j++){
  if(tds[j].title.toLowerCase().indexOf(listName.toLowerCase()) != -1){
   webpartZone = tds[j].parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;   
      webpartRow = webpartZone.parentNode.parentNode.parentNode;
     }
 }
 if(webpartZone){
  webpartRow.style.display = display;
  var bodyDiv = webpartZone.children[1].children[0].children[0];
  if(scrollable){
   bodyDiv.style.height = height;
   bodyDiv.style.overflow = "auto";
   bodyDiv.style.display = display;
  }
 }
}

</script>

 

Embedding JavaScript in SharePoint Pages

August 20th, 2007 by chadclarke

The best method to embed custom javascript in SharePoint pages is to create a .js file and then include it in the SharePoint Page.  If you would like to include javascript functions in the onload event of a sharepoint page, use the _spBodyOnLoadFunctionNames array. Include the push method in your script with the title of your function.  The function should not include parameters…

 <script>
function runOnLoad(){

}
_spBodyOnLoadFunctionNames.push("runOnLoad");
 </script>

Hope this helps!!!  Good luck in the World of SharePoint!

Bug in SharePoint Designer Found!

August 20th, 2007 by chadclarke

SharePoint Designer is an excellent tool!!!  As long as you don't use Web Part Connections!!!  SharePoint Designer implants code everytime you open a page with web part connection(s), and then when you save it, the page will error that a connection with connection id ###### already exists… To fix the page, open it in sharepoint designer and remove all child nodes of the webpart manager node.  Hope this helps!

My First SharePoint Blog

August 20th, 2007 by chadclarke

Hey all,

I am an IT Consultant with Levi, Ray, and Shoup, Inc.  I attended their Portal University in July – October '05 and have worked with LRS as a SharePoint Consultant ever since.  I have been on numerous successful engagements deploying SharePoint 2003, MOSS 2007, InfoPath 2003 and 2007.  I have a strong foundation in many languages including but not limited to MySQL, PHP, SQL, C#, VB.NET, XML, XSLT, JavaScript, CSS, HTML, ASP.NET, and AJAX 1.0 for ASP.NET 2.0.  I have worked with phpmyadmin, phpdev, SharePoint Designer, Visual Studio 2003, Visual Studio 2005, SQL Server 2000, and SQL Server 2007.  I am currently taking a look at the new Visual Studio ORCAS.  I also have attained my MCSD in C#.  Wish me luck on my journey's in the World of SharePoint, please share the good and bad with me right here on my blog!  More to come soon!