JQuery for Everyone: HTML Calculated Column
Christophe, at Path to SharePoint, created one of the most important scripts for quickly and easily punching up the List View and List Form web parts, the HTML Calculated Column. His creative uses for this mashup of data and HTML always inspires me.
Thats why I wanted to rewrite his script for jQuery (you still need to make sure your calculated column has a <DIV> tag using all caps, but it no longer has to start with it). The thing that shocked me the most: ExpGroupRenderData was rewritten to one line of code!
<script type="text/javascript" src="http://www.google.com/jsapi"></script> <script type="text/javascript"> //load jQuery google.load("jquery", "1.2.6"); </script> <script type="text/javascript"> //make a fn for reuse $.calcHTML = function() { //loop through TDs moving text node to html $("td.ms-vb2,td[id$='Calculated'],td.ms-stylebody,td.ms-formbody").filter(":contains(<DIV)").each(function(){ $(this).html($(this).text()); }); }; //call calcHTML on DOM ready for ungrouped rows $(function() { $.calcHTML(); if (showpreview1) { //check for preview script $("td.ms-vb-title").bind("mouseover", function(){ showpreview1(this); $.calcHTML(); }); } }); //replace ExpGroupRenderData, call calcHTML for grouped rows function ExpGroupRenderData(htmlToRender, groupName, isLoaded) { $("#tbod"+groupName+"_").attr("isloaded",isLoaded).html(htmlToRender).show("fast",$.calcHTML()); } </script>
- JQuery for Everyone: Accordion Left Nav
- JQuery for Everyone: Print (Any) Web Part
- JQuery for Everyone: HTML Calculated Column
- JQuery for Everyone: Dressing-up Links Pt1
- JQuery for Everyone: Dressing-up Links Pt2
- JQuery for Everyone: Dressing-up Links Pt3
- JQuery for Everyone: Cleaning Windows Pt1
- JQuery for Everyone: Cleaning Windows Pt2
- JQuery for Everyone: Fixing the Gantt View
- JQuery for Everyone: Dynamically Sizing Excel Web Parts
- JQuery for Everyone: Manually Resizing Web Parts
- JQuery for Everyone: Total Calculated Columns
- JQuery for Everyone: Total of Time Differences
- JQuery for Everyone: Fixing Configured Web Part Height
- JQuery for Everyone: Expand/Collapse All Groups
- JQuery for Everyone: Preview Pane for Multiple Lists
- JQuery for Everyone: Preview Pane for Calendar View
- JQuery for Everyone: Degrading Dynamic Script Loader
- JQuery for Everyone: Force Checkout
- JQuery for Everyone: Replacing [Today]
- JQuery for Everyone: Whether They Want It Or Not
- JQuery for Everyone: Linking the Attachment Icon
- JQuery for Everyone: Aspect-Oriented Programming with jQuery
- JQuery for Everyone: AOP in Action - loadTip Gone Wild
- JQuery for Everyone: Wiki Outbound Links
- JQuery for Everyone: Collapse Text in List View
- JQuery for Everyone: AOP in Action - Clone List Header
- JQuery for Everyone: $.grep and calcHTML Revisited
- JQuery for Everyone: Evolution of the Preview
- JQuery for Everyone: Create a Client-Side Object Model
- JQuery for Everyone: Print (Any) Web Part(s) Plugin
- JQuery for Everyone: Minimal AOP and Elegant Modularity
- JQuery for Everyone: Cookies and Plugins
- JQuery for Everyone: Live Events vs. AOP
- JQuery for Everyone: Live Preview Pane
- JQuery for Everyone: Pre-populate Form Fields
- JQuery for Everyone: Get XML List Data with OWSSVR.DLL (RPC)
- Use Firebug in IE
- JQuery for Everyone: Extending OWS API for Calculated Columns
- JQuery for Everyone: Accordion Left-nav with Cookies Speed Test
- JQuery for Everyone: Email a List of People with OWS
- JQuery for Everyone: Faster than Document.Ready
- jQuery for Everyone: Collapse or Prepopulate Form Fields
- jQuery for Everyone: Hourly Summary Web Part
- jQuery for Everyone: "Read More..." On a Blog Site
- jQuery for Everyone: Slick Speed Test
- jQuery for Everyone: The SharePoint Game Changer
- JQuery For Everyone: Live LoadTip
Hey! Is it Christmas already? ;-)
Very interesting, Paul… and now I have a good reason to learn jQuery!
One question: did you test this script for boxed and newsletter views?
Newsletter works. Adding ,td.ms-stylebody to the selector list makes it work on boxed (I’ll make that change above).
I’m working on Preview, trying to get the calcHTML to fire…
@Christophe,
Thanks for pointing out the multiple view styles. It took some detective work but I figured out a way to adjust the mouseover behavior for Preview style as well.
This a great little gem; even for SharePoint Designers
Excellent solution. It’s one of those, “Wow…why didn’t I think of that?” solutions that everybody in SharePoint Land needs to know about. Great work, both of you!
Hi Paul,
Christophe have a javascript to make this work in calendar view as well. Would it be possible to make the jquery handle that as well. I really would like to get a way from having to start with a tag.
You are both some kind of heroes, thanks a lot!
Hi Paul,
Excellent article. Thanks for that. I am having a sharepoint site in which I am trying to create a text column in the tasks list. However, this column should be from client side script. Can you tell me how I can do this using Jquery, it would be glad if you can post some pseudo code on that.
Thanks,
yeshwanth
Yeshwanth,
I would not try to add a column. I would create a column and replace its contents with mine. The best examples of this uses the calcHTML technique. Christophe’s site has several examples and I wrote a jquery version of that code (it’s also included in several of my other projects).
Great ideas from both you and PathToSharepoint bloggers.
However, I have a Dataview WP that is displaying the html code of a rich text column. Is there a CEWP that can hide html code on the page?
@ Robert, yes you can definitely do that with the right code
@ All
I use this script on my calendar to display extra data via fields in a calculated event title. I then use a script that creates a popup that displays the extra data when the item is moused over. It is working really great, thanks!
For the calendar view, you can add this line to work on the event titles (if ONLY using all-day events):
$(”td.ms-cal-defaultbgcolor”).filter(”:contains(<DIV)").children('a').each(function(index) {
$(this).html($(this).text());
});
The script throws an error in IE 8:
Line: 961
Error: ’showpreview1′ is undefined
What is the purpose of showpreview1?