The following is an excerpt from chapter 7 of my book SharePoint 2007 and 2010 Customization for the Site Owner. I keep getting questions on this so I thought I’d post it here. (You should still by the book!)
Adding a Content Editor Web Part to a view page like "Allitems.aspx" is a great way of customizing list and library views in SharePoint 2007. This generally had no negative impact, was easy to do and produced some major improvements with little work.
The Problem in 2010?
SharePoint 2010 treats view pages with added web parts as non-views and removes many view related features. I.e. adding a web part to a view breaks some things…
Here's a typical Task list All Tasks ("Allitems.aspx") view with the view menu clicked:
Note these features:
- The name of the view is displayed: Subsite 3 > Tasks > All Tasks
- There are ribbon tabs for Browse, Items and List (or for a library, Documents and Library)
- There is a dropdown arrow after "All Tasks" in the crumb trail
Here is the same view after the addition of a Content Editor Web Part (and the JavaScript to color code the task list):
Note what's missing:
- The name of the view in the crumb trail is missing
- The ribbon tabs for Items and List are missing
- The dropdown arrow after "All Tasks" in the crumb trail is missing
- You can still get to the ribbon tabs, but you have to first click a row in the list:
The Fix?
Don't add web parts to a 2010 view! (Duh) Instead, edit the page using SharePoint Designer 2010 and add your JavaScript code between the end tag for the Web Part Zone and the end tag for the PlaceHolderMain content tag.
You can either embed the JavaScript:
<script type="text/javascript">
// js code here
</script>
Or you can link to a text file with the JavaScript that you've uploaded to a library:
<script src="../../SitePages/ColorCodedTaskList.txt" type="text/javascript"></script>
.