Lookup columns are both useful and a little odd in how they’re implemented in SharePoint list views. I wrote a bit about this in a previous post and showed one example on how to deal with Lookup column content. This post shows an alternative – and possibly more useful approach.
We’ll change the default link in the lookup field to a link that filters the current list by the lookup field value. Yes, users can also use the filter built into the column header – this is just another way to implement it. I also think this is a bit more intuitive for users.
At the end of the day, this is just another example of custom link ‘building’ with CSR.
Sample File: CSR_LookupSelfFilter.js
With ‘Theme’ being the internal name of the Lookup field that we’re filtering on. Fairly straightforward.
Now we also need to add a ‘reset’ link to the web part so that users can get back to the default view. Otherwise, they could get stuck in a dead end after selecting a filter value. There are all kinds of ways to implement this, for simplicity’s sake we just updated the title text and link.
Before:
Obviously you don’t *actually* have to change the text of the web part header – just the URL. But again, it seems like better UX.
Hope this is useful.
References:
JS Link and CSR Page