Adding a custom action to a callout based on the file type

December 12, 2014

Back in October 2013 I wrote a post on how you could add your custom actions in a callout like this (Adding a custom action to a callout in SharePoint 2013):

Callout with a custom action

Callout with a custom action

This time I had the requirement to only add an action for a specific file type.

Solution

The solution is rather simple. Here is the code from my previous post:

With this piece of code you can add a custom callout action for all documents, so what we need to implement is a check to see if the document is for example a PDF document. This information can be retrieved from the renderCtx object like this, and to be more specific, if you click to open the callout the renderCtx object contains all the information about the current item:

renderCtx.CurrentItem

renderCtx.CurrentItem

The file type can be retrieved like this:

Once you know the file type, you could implement the check like this:

On the highlighted line a check is in place to see if the current item is a PDF document, if that statement is true, the custom action gets added, otherwise nothing will be shown.

PDF document with a custom action

PDF document with a custom action

Word document does not get the custom action

Word document does not get the custom action

 

Comments