Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

SharePoint 2013 JSLink hide columns through calculated fields

Tags: field column

So you've probably come across heaps of cool articles that show you how to create fancy rendering solutions using JS Link Templates. But every example tends to deal with only one Field (Template.Fields) or all fields (Template.Item)

If you want to mess with more than one field it is really simple. Just add more to the array.
I.e.
Template.Fields = { "Budget" : {"View":somefunction}};
becomes
Template.Fields = { "Budget" : {"View":somefunction},
{"Timeline" : {"View":someotherfunction}}};

Sometimes you want to use the value of a field without actually showing it as a column. For example when you're adding icons to other fields or enhancing a column with extra info.
You'll notice is that the rendering template will fail if you do not include the desired field in your view, causing it to appear as extra annoying column.

Here is a trick I stumbled across by accident:
When you include a calculated column in your view, all referenced columns will become available to the current context through ctx.CurrentItem. So if you want to use the value of a field but don't want to include it as an extra column in the view, maybe you've got a calculated field you can abuse.
In my case I had following calculated column
BudgetStatus = [Actual Budget]/[Estimated Budget]
That made all three fields available in my context.
And now I wanted to include the Delivery Date for some funky rendering without making it a column? Simple. My new Budget Status looks like this:
BudgetStatus = ([Actual Budget]/[Estimated Budget]) + ([Delivery Date] * 0)

I know it's cheating. But hey, sometimes you have to cheat to get things done!



This post first appeared on SharePoint Training, Alex Dean, please read the originial post: here

Share the post

SharePoint 2013 JSLink hide columns through calculated fields

×

Subscribe to Sharepoint Training, Alex Dean

Get updates delivered right to your inbox!

Thank you for your subscription

×