Saturday, April 20, 2013

Formatting Texts in a SharePoint List Item columns

This could be an old-school  thought of wanting to apply different formats to the values stored in list columns.

Well, one can definitely go a number of ways to achieve that, but here’s an approach when an end-user can drop some code in a calculated field to achieve this very easily and more precisely, getting to a number of different formatting styles.

Format 1: Displaying a Hyperlink Text in a calculated column

Create three columns in a list as below:

Column1: [ActualURL] of type “Single line of text”. (We will store values like “http://neerajch.blogspot.com” in this column)

Column2: [URLTitle] of type “Single line of text”. (We will store values like “NeerajCh” in this column)

Column3: [HyperlinkHTML] of type “Calculated”.

Type the below in the Formula box:

=CONCATENATE("<DIV><a href='",ActualURL,"'>",URLTitle,"</a></DIV>")

Select “Number (1, 1.0, 100)” in the [Data Type returned from this formula] section.

Leave the “Automatic” in [Number of Decimal Places].

That’s it. Hit OK and create one new list entry with values mentioned above. [Title] can be anything.

You should see something like this. Hurray !!!

image

Now that “Concatenated” formula piece can be a real handy and fruitful, if used wisely. Let’s see another small example.

Format 2: Displaying a Hyperlink Text in a calculated column as BOLD

With the same configurations for the list columns as above, we modify the formula to include <b> & </b> tags within the <DIV>.

=CONCATENATE("<DIV><b><a href='",ActualURL,"'>",URLTitle,"</a></b></DIV>")

And now you see something like this:

image

Wow, I know, you must be smiling. Smile Nothing great here!! Just plain HTML. And that is my intent.

Let the things be as simple as they can be, for this has to be done by an end user not a developer/designer.

So the end users now have a great handy tool and can make it even powerful, if they can extract more complex HTMLs from their peer developers and embed here.

No comments: