This post covers another column type for use with CSR overrides. Lookup columns have what I consider an irritating default display characteristic in that they are displayed as a hyperlink to the lookup list item.
Where the link goes to:
The majority of the times I’ve seen a Lookup used, they are simply a list of items to select in a dropdown or radio buttons – like a category. In this case the hyperlink and displaying the form are useless (to me). Every so often the lookup list has a few other fields, like Description, etc. in that case the link can be a bit more useful, but it still seems to be more of a distraction from a user experience (UX) perspective.
What I’d like to see is the Lookup value – the same text – displayed without the hyperlink. I can get this value using the following:
ctx.CurrentItem.Theme[0].lookupValue
Or, more generically:
ctx.CurrentItem.[internalName][0].lookupValue
You can also access two other properties of the item. The properties are: isSecretFieldValue, lookupId, and lookupValue. And no, right now I have no idea what the heck ‘isSecretFieldValue’ is other than a Boolean value.
Note: OK. I looked it up. There’s one post under ‘isSecretFieldValue’ here – and if set to ‘True’ it apparently hides the values of the Created By and Modified By values in the form. Huh.
Back to our Lookup column.
As with several other column types, the Lookup column can contain more than one item and is stored as an array. As with those other column types you can also check how many items are contained in the column value by checking the length of the array:
ctx.CurrentItem.[internalName].length
Once an override is put into place using this approach, the list view now looks something like this:
Definitely cleaner.
Sample code for this example can be found here.