Cal11 calculator

Put Html in Sharepoint List Calculated Column 2013

Reviewed by Calculator Editorial Team

SharePoint 2013 calculated columns are powerful for performing calculations on list data, but they have limitations when it comes to displaying formatted text or HTML content. This guide explains how to work around these limitations to display HTML in a calculated column.

How to Put HTML in a SharePoint 2013 Calculated Column

SharePoint 2013 calculated columns are designed primarily for mathematical calculations and text concatenation. However, you can display HTML content by using a combination of calculated columns and JavaScript.

Method 1: Using Calculated Column with HTML Entities

The simplest way to display basic HTML formatting is to use HTML entities in your calculated column formula. Here's how:

  1. Open your SharePoint list and click on the "List Settings" link in the Settings menu.
  2. Click "Create Column" and select "Calculated (calculation based on other columns)" as the column type.
  3. Enter a name for your column and select "Number" or "Single line of text" as the data type.
  4. In the formula box, enter your HTML content using HTML entities. For example:
    <div style="color:red">Warning</div>
  5. Click "OK" to create the column.

Note: This method only works for basic HTML formatting. Complex HTML or JavaScript will not render properly in a calculated column.

Method 2: Using JavaScript with Calculated Column

For more advanced HTML display, you can combine a calculated column with JavaScript:

  1. Create a calculated column as described in Method 1, but leave the formula empty.
  2. Edit the list view where you want the HTML to appear.
  3. Click "Add Column" and select your calculated column.
  4. Click "Edit Column" and then "Edit HTML Source".
  5. Add JavaScript to dynamically insert HTML content. For example:
    <script type="text/javascript">
    function displayHTML() {
      var htmlContent = '<div style="color:blue">Dynamic Content</div>';
      document.write(htmlContent);
    }
    </script>
    <script type="text/javascript">displayHTML();</script>
  6. Save your changes.

Warning: This method requires SharePoint Designer or direct access to the list view HTML. It may not work in all SharePoint environments.

Limitations and Workarounds

There are several limitations to displaying HTML in SharePoint 2013 calculated columns:

  • Security Restrictions: SharePoint blocks certain HTML tags and attributes for security reasons.
  • JavaScript Limitations: JavaScript execution is restricted in calculated columns.
  • Rendering Issues: Complex HTML may not render properly in all browsers.

Workarounds include:

  1. Using simpler HTML with basic formatting tags (bold, italic, color)
  2. Creating a separate web part with custom HTML and JavaScript
  3. Using SharePoint Designer to modify list views directly
  4. Creating a custom SharePoint solution with Visual Studio

Example: Creating a Calculated Column with HTML

Let's create a calculated column that displays a status message with different colors based on another column's value.

Step-by-Step Example

  1. Create a new calculated column named "StatusHTML" with the formula:
    =IF([Status]="Approved", "<div style="color:green">Approved</div>", IF([Status]="Pending", "<div style="color:orange">Pending</div>", "<div style="color:red">Rejected</div>"))
  2. Add this column to your list view.
  3. The column will now display colored status messages based on the "Status" column values.

Tip: For more complex formatting, consider using a SharePoint Designer workflow or a custom web part solution.

Troubleshooting Common Issues

HTML Not Displaying Properly

If your HTML isn't displaying correctly:

  • Check that you're using proper HTML entities in your formula
  • Verify that the HTML tags you're using are allowed in SharePoint
  • Try simplifying your HTML to basic tags first

JavaScript Not Executing

If your JavaScript isn't running:

  • Ensure you have the proper permissions to edit list views
  • Check that your JavaScript code is properly formatted
  • Consider using SharePoint Designer for more control over JavaScript execution

Performance Issues

If your list is slow with HTML in calculated columns:

  • Limit the number of calculated columns with HTML
  • Consider using a separate web part for complex HTML content
  • Test with a small subset of data first

FAQ

Can I use CSS classes in my HTML?

SharePoint 2013 has limited support for CSS classes in calculated columns. You may need to use inline styles for consistent rendering.

Will my HTML display the same in all browsers?

SharePoint 2013 supports basic HTML rendering, but complex layouts may not display consistently across all browsers.

Can I use images in my calculated column HTML?

Yes, you can use the <img> tag with absolute URLs to display images in your calculated column.

Is there a limit to how much HTML I can use?

SharePoint has a limit on the length of calculated column formulas. For complex HTML, consider using a separate web part solution.

Can I update the HTML after it's been created?

Yes, you can modify the calculated column formula at any time to update the displayed HTML.