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>
.
9 comments:
I use content editor web parts in 2007 views not for javascript, but for just instructions to my users. Any suggestions for that? Thanks.
Anonymous,
The 2007 does not have the issue with web parts added to a view page. Just use the CEWP as usual.
Mike
YEs - it works great in 207! I'm sorry I wasn't clear, but my problem is when I migrate that page to 2010 it doesn't work. I still want to be able to put some instructions in a CEWP onto the library view page. Any ideas on how to approach that? Thanks again!
Catherine
Catherine,
You will need to edit the page using SharePoint Designer and add your comments there. This would be best done after the page has been migrated to 2010.
Adding a CEWP, or any other web page, to a 2010 view page will interfere with the ribbon.
Mike
Mike, Just the right fix that I needed! I suppose getting jQuery to fire after the DOM has loaded would work as well?
> I suppose getting jQuery to fire after the DOM has loaded would work as well?
Yes... (as long as you have the jQuery libraries loaded of course)
follow up for Catherine -
You can do what you want to do. I couldn't figure it out either.
Link to how to add CEWP directly to a list or library http://blog.pentalogic.net/2010/07/how-to-edit-list-forms-sharepoint-2010/
-Rachel
I can't edit that zone, it's yellow indicating it's a "frozen" section. Is there a trick?
Answering my own issue: In order to edit the yellow sections you must click on Advanced Mode in the ribbon.
Post a Comment