Make Doc Icon Type Clickable In SharePoint Online/SharePoint 2013

You may have seen some new behavior in SharePoint online where Doc Icon links are not clickable in the document library after migration from SharePoint 2010 to SharePoint Online/SharePoint 2013.

The following code can be added as a CEWP in each document library View wherever you need clickable Doc Icon functionality. This is a generic script and can be added to any SharePoint library without making any changes.
  1. <script type="text/javascript">  
  2.     (function () {  
  3.         var replaceCtrl = {};  
  4.   
  5.         replaceCtrl.Templates = {};  
  6.         replaceCtrl.Templates.Fields = { 'DocIcon': { 'View': CustomIcon } };  
  7.         SPClientTemplates.TemplateManager.RegisterTemplateOverrides(replaceCtrl);  
  8.     })();  
  9.   
  10.     function CustomIcon(ctx) {  
  11.         if (ctx.CurrentItem.FSObjType == '1') {  
  12.             var ret = "<a href=\"" + ctx.CurrentItem.FileRef + "\">" +  
  13.                       "<img width='16' height='16' title=\"" + ctx.CurrentItem.FileLeafRef + "\" " +  
  14.                       "class='ms-draggable' alt=\"" + ctx.CurrentItem.FileLeafRef + "\" " +  
  15.                       "src=\"/_layouts/15/images/FOLDER.GIF\" border='0' DragId='0'/></a>";  
  16.         }  
  17.         else {  
  18.             var ret = "<a href=\"" + ctx.CurrentItem.FileRef + "\">" +  
  19.                       "<img width='16' height='16' title=\"" + ctx.CurrentItem.FileLeafRef + "\" " +  
  20.                       "class='ms-draggable' alt=\"" + ctx.CurrentItem.FileLeafRef + "\" " +  
  21.                       "src=\"/_layouts/15/images/" + ctx.CurrentItem['HTML_x0020_File_x0020_Type.File_x0020_Type.mapico'] + "\" " +  
  22.                       "border='0' DragId='0'/></a>";  
  23.         }  
  24.         return ret;  
  25.     }  
  26. </script>  
Ebook Download
View all
Learn
View all