Preview metadata in list view on mouseover – updated version


18.09.2011 I have added a bit more functionality. The CEWP code and the file “PreviewMetadata.js” has changed. Re-read this article for details.


This is a remake of a previously posted solution for previewing an item in a list when hovering over the table row or a custom image. You find the code below, but first an overview of the features.

List view
IMG

Preview on hover
IMG

This solution works in both SharePoint 2007 and in SharePoint 2010, but the code is different for the two. It is tested in plain list (and document library) views with grouping and paging, and in calendar views. You can specify which columns to preview, or have the full DispForm array of fields. If you have multiple list view web parts in one page, you can specify which lists to activate this feature on.

How to use

Download the code for the file “PreviewMetadata.js” from here. Ensure you pick the right version (SP2007 or SP2010). Upload the file to a shared document library, or put it in a folder using SharePoint Designer. You then insert a ContentEditorWebPart (CEWP) below the list view web parts in the page. You must modify the script src to the file “PreviewMetadata.js”, and if you like, to the jQuery library.

Hints

Read here how to find the list Guid and the FieldInternalName for your list fields.

CEWP code for SharePoint 2007

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script type="text/javascript" src="/test/English/Javascript/PreviewListItems/PreviewMetadata.js"></script>
<script type="text/javascript">
config = {arrOfFieldsToShow:[],
		  hideIdColumn:true,
		  activeListGuids:[],
		  hideCreatedAndModified:true,
		  hideFormLabel:false,
		  hoverDelay:100,
		  hoverImg:{active:true,
		  			path:'/_layouts/images/chm16.gif',
		  			height:'12',
		  			width:'12',
		  			prependTo:'LinkTitle',
		  			hoverImgDescription:'Hover over this image in the list to preview the list item'}};
initjLoadMe(config);
</script>

CEWP code for SharePoint 2010

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script type="text/javascript" src="/test/EMSKJS/PreviewMetadata/PreviewMetadata.js"></script>
<script type="text/javascript">
config = {arrOfFieldsToShow:[],
		  hideIdColumn:true,
		  activeListGuids:[],
		  hideCreatedAndModified:true,
		  hideFormLabel:false,
		  hoverDelay:100,
		  hoverImg:{active:true,
		  			path:'/_layouts/images/chm16.gif',
		  			height:'12',
		  			width:'12',
		  			prependTo:'LinkTitle',
		  			hoverImgDescription:'Hover over this image in the list to preview the list item',
		  			openInDlg:true}};
		  			
initjLoadMe(config);
</script>

Note to SharePoint 2010 users:
Add this code to a text file and put it in a document library, then use the content link option on the CEWP to link to this code. This is necessary to overcome a possible “bug” in the CEWP handling when editing a SP2010 page where the HTML is accumulated when editing the page.

This tip is also recommended for SharePoint 2007 users, but is not absolutely necessary.

Parameters explained
  • arrOfFieldsToShow: Array of FieldInternalNames to show. Leave empty to show all fields from DispForm. (*) To hide the field name for individual fields in the preview, put # as a suffix to the name like this: ['Title#'].
  • hideIdColumn: true or false. If true, the ID column must be placed to the far right in the view.
  • activeListGuids: Array of the Guids of the lists to activate this feature in. If left empty, all list view web parts will be active. Use this if you have more than one list view web part in the page and does not want to activate this feature for all web parts.
  • hoverImg: If the parameter “active” is true, the preview will be shown when the user hovers over the image specified. If false, the preview will be shown when the user hovers over the table row.
  • hideCreatedAndModified (*): true or false. Determines whether or not to show the “Creates by” and “Modified by” at the bottom of the preview.
  • hideFormLabel (*): true or false. Determines whether or not to hide the field names column entirely. When set to true, this one overrides individual field settings under “arrOfFieldsToShow”
  • hoverDelay (*): The delay in milliseconds from the user hovers over the image / row until the preview is triggered. If used with “hover” over the entire row, set this higher to prevent shoving all previews when the user swipes the mouse over multiple rows.
    • active: true or false.
    • path: The path to the image used as “hover image”.
    • height: Image height in pixels.
    • width: Image width in pixels.
    • prependTo: The FieldInternalName of the field to prepend the hover image to. The Title field with menu has FieldInternalName “LinkTitle”
    • hoverImgDescription: The Description text on the “instructions” shown above the list view.
    • openInDlg: (SharePoint 2010 only) Defines whether the form is opened in a dialog when the user clicks the hover image.

(*) New in v2.3 for SharePoint 2007 and v1.1 for SharePoint 2010.


Ask if something is unclear.
Alexander

117 Responses to “Preview metadata in list view on mouseover – updated version”

  1. Sabin Says:

    Hello Alexander,
    Thank You very much for your work. I really appreciate it. I am using sp2010 and downloaded latest feature. I have a question, can we make a hover work for a specific column rather than in title column.

    For example

    I have

    Program, program status, program comments, Page, Page status, page comments.

    Columns in a sharepoint custom list. So when i hover over Program or a Page, i want it to popup items in program status and program comments in context of program. But when i hover over Page can i pop up page status and page copmments in a box.

    Is thsi functionality possible with our solution. If yes can you provide me place where i need to make adjustments.

    Thank You

    • Alexander Bautz Says:

      Hi,
      This is not possible as the solution lets you have only one “hover action” in each row.

      Alexander

  2. AP Says:

    Alexander

    I have sent the screen shots and CEWP code to your email id. Thanks again for your assistance!

    AP

  3. GR Says:

    Hi, did you get a chance to diagnose what AP posted? I am having the exact same issue in SP2010 Enterprise calendar view. Just getting the blank hover bar. Tried everything listed here with no content showing.

    • Alexander Bautz Says:

      Hi,
      Yes, AP found that it was an error occurring when more than 5 items was listed in one day. I have not had the time to verify it yet, but it’s on the “stuff to do” list.

      Alexander

    • Alexander Bautz Says:

      Hi,
      I was mistaking regarding the cause of the “blank popup error”. Could you help us shed some light upon the reasons for this behavior?

      I have not been successful in recreating this bug.

      Alexander

    • GR Says:

      I have a single calendar with 9 overlays and 25 views (not that this should matter). There is a lot of content displayed at once which works great however this overlay would really help. I have the calendar embedded as a web part on a page. Right beside it I have a hidden CEWP which points to the 2010 CEWP code in a text file using the Content Link. That text file and the .js file are saved in a document repository. The text file has an absolute URL pointing to the .js file. When I hover over the calendar entries I get a very thin sliver of the overlay with no content in it. I’ve tried putting individual field names in the arrOfFieldsToShow with no luck. In fact, the sliver of overlay goes away completely when I do that but I could have my syntax wrong. Otherwise I made no changes to the code shown above except the path to the .js file.

      Hope this helps. Thanks so much for your advice and hard work!

    • GR Says:

      Any thoughts? Still just a blank line on mouseover.

    • Alexander Bautz Says:

      Sorry, but I have not been able to reproduce the error and without being able to see it “hands on” in a system experiencing this error, there is nothing I can do.

      If it were possible or me to log into your site end have a look, I might be able to pinpoint the cause.

      Alexander

    • GR Says:

      It’s working now. We have heavily customized the master page to not look out of the box. During the process other page templates were customized and we slowly rolled each one back to stock. That’s the only thing I can think of that has resolved it. The only issue now is the delay, it takes a couple seconds or so for the data to appear in the hover.

  4. Jameel Says:

    I am not sure if everyone has had issues with this, but modifying the css of the jLoadMe does not actually change anything. That is, changing

    .css({‘position’:'absolute’,
    ‘left’:pX,
    ‘top’:pY,
    ‘background-color’:'#fafafa’,
    ‘border’:’2px solid #C3D940′,
    ‘padding’:3,
    ‘width’:contentWidth})

    did not actually result in changes.

  5. Sabin Says:

    Thank You for you answer Alexander,
    One more question,In arrOfFieldsToShow i want to add column named First Name. How do i add that in to the array field, i looks like it only takes one word.

    It is taking Name but it is not taking First Name.

  6. Sabin Says:

    Thank You Alexander,
    Question, Is it possible to click on the item inside the pop up box. When you take mouse off the field pop up disappears.

  7. Sabin Says:

    Hey Alex,
    Can we idle pop up box for couple of seconds when hovered so that end user can click item inside the box.

  8. Mike Says:

    Great post, but I’m having trouble downloading the PreviewMetadata.js file… clicking your link just takes me to a “internet explorer cannot display…” blank page. Is there anyplace else I could get the file?

    Thanks!

  9. Connie Churby Says:

    Can I hover over and display a description on (just) one word in the column.

    Connie

    • Alexander Bautz Says:

      Hi,
      No, it’s either the “row” or an image specified as “hoverImg”.

      Alexander

  10. Sabin Says:

    Alex,
    In a pop-up box, some of the texts are going out of the box. IS there a way to wrap the content inside the pop-up box.

    Thank You

    • Nick D Says:

      Which browser are you using? It works for me with no issues on IE8. I did notice that it goes outside the box on Chrome, but then again, SharePoint in general doesn’t work well in Chrome.

    • Alexander Bautz Says:

      I’m in the process of redoing the solution for SharePoint 2010 – is it SP2010 you are using?

      Alexander

    • Sabin Says:

      Alex,
      Yes I am using SP2010
      Thank You

    • Jason Evans Says:

      Hi Alex, is there a code fix available regarding having the text wrap itself within the preview form text box?

      Thanks again!

  11. Sabin Says:

    Nick I am using IE8 but it works fine in Firefox. Is there anything i can do to fix this

    Sabin

  12. Sabin Says:

    Alex,
    Yes I am using SP2010

    Thank You

  13. Trevor Habkirk Says:

    Excellent work as always, Alexander.

    I’ve added a parameter to the config – enableListView:false . In our situation we don’t want to see the metadata preview for list views, only calendar views. I’ve also customized the appearance to look somewhat like a post-it note. Works like a charm and our users love it!

    Trevor

  14. sabin Says:

    Hi,
    How do we make the pop up box wider. Is there something we can change in javascript file?

  15. daniel Says:

    Is there a way to display the content of the pop up in a seperate CEWP instead? I would like to display the content in a fixed place for the user when they hover over a list item and can’t figure out how to achieve that.

    Thank you in advance.

    Daniel

    • Alexander Bautz Says:

      The content of the preview is placed in a container with ID “jLoadMe”. Look in the script for this container ID, and insert the ID of the container you want to use in stead. You will have to bypass the part of the script that positions the container “floating”, but this should be fairly simple.

      Alexander

  16. John Says:

    Maybe someone can help me here. I am working with MOSS 2007 and I have got the previewmetadata scipr working perfectly. Thanks Alexander by the way, excellent stuff as usual. I am using it to display contact numbers for technicians on a site. Problem is when they hover over the line item the number pops up but as soon as they move the mousze it goes away and they need to move the mouse to select their IP phone to make the call. I would like it to pop up onclick, and to go away onclick if at all possible. if so, how do I do this? Any help would be appreciated, I am new to Jquery and javascript so I do apologize for asking such a silly question to most of you.

    • Alexander Bautz Says:

      Hi,
      This code does not have support for what you ask, but you can play around with this bit of code found various places:
      $(“#jLoadMe”).html(”).hide();”

      If you comment it out, the preview will not disappear. I’m afraid I cannot promise any updates to this code.

      One question though – why not have the phone number visible in the view if this is what the users want to reach?

      Alexander

    • jaymarzian Says:

      Thanks Alexander, I will play around some more with this and see what I come up with. This list has hundreds of rows, with multiple visible columns (the phone numbers are not in the view, because it would look to cluttered). All that the popup displays is the phone numbers of both the primary technician and the backup technician, both office and cell numbers.

  17. bgunter Says:

    I dont know if I’m doing something wrong but i just keep getting this skinny textbox with no content in it. I followed the code exactly and even added specific columns. Can I get some help on getting this to work correctly?

    config = {arrOfFieldsToShow: ['Title','Location'],
    hideIdColumn: true,
    activeListGuids:[],
    hideCreatedAndModified: true,
    hideFormLabel: false,
    hoverDelay: 100,
    hoverImg:{active:true,
    path:’/_layouts/images/chm16.gif’,
    height:’12′,
    width:’12′,
    prependTo:’LinkTitle’,
    hoverImgDescription:’Hover over this image in the list to preview the list item’,
    openInDlg:true}};

    initjLoadMe(config);

  18. Shibby Says:

    Replace this $(“#jLoadMe”).html(”).hide();
    with this:
    setTimeout(function(){$(“#jLoadMe”).html(”).hide();}, 3000);

    to set the time for the Preview popup

  19. Jery Says:

    Hi Alex,
    I’am using SharePoint 2010, I can’t to display tooltip with calendar using Custom Form with Infopath (displayifs.aspx), not default Display form. You can help me?
    Thanks,

  20. tenillebennett Says:

    Hi Alex, I wonder if your script could me modified to fit my requirements. I need some urgent help to create some ECMA scripts for my project. I have an html map of europe with 39 countries marked out in hotspots. I have a SharePoint 2010 list with 3 fields; country, description, and url.

    I want to create an ECMA script to create a pop up with the country name and description when a user hovers over that country on the html map. I will be pasting this code into a Content Editor Web Part for use on my Intranet. I need to retrieve and filter the list data, then bind to the onmouseover event to trigger the pop up with the information.

    Can anyone help me with the script, I am new to Javascript. my HTML map code looks like this:

    • Alexander Bautz Says:

      Read here how to post code in comments

      Repost the code and I’ll take a look.

      Alexander

  21. tenillebennett Says:

    Hi Alex, my code looks like this, I have no idea what i am doing!

    I can’t find how to put code in here but here is a link to a forum i have posted in:

    http://social.msdn.microsoft.com/Forums/en-US/sharepointcustomization/thread/d2fb4423-952b-42a2-beb5-37a42bf2f073

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.

Join 435 other followers