Kate
Kate

Reputation: 1495

SharePoint 2013 open document in a Display Form

I created a document library in SharePoint and when I click on a document in a list view (All Documents), it opens the file. Is there a way to change it to open a Display Form for the selected document instead (javascript, ....)? I know you can click ellipses and elipses angain and then View Properties, but I need the actual document link (under the 'Name' column) to do that. Thank you in advance!

Upvotes: 4

Views: 2859

Answers (1)

Vadim Gremyachev
Vadim Gremyachev

Reputation: 59358

Since in SharePoint 2013 Client-Side-Rendering (CSR) is a default rendering mode, below is demonstrated how to customize LinkFilename field rendering via CSR.

JavaScript template file

How to render LinkFilename field with a link to a Display Form page

(function () {


    function renderLinkFilename(renderCtx) {
      var item = renderCtx.CurrentItem;
      var documentDisplayFormUrl = renderCtx.displayFormUrl + '&ID=' + item.ID; //construct document Display Form Url
      return '<a href="' + documentDisplayFormUrl + '">' + item.FileLeafRef + '</a>'; 
    }



    function registerRenderer()
    {
      var ctxView = {};
      ctxView.Templates = {};
      ctxView.Templates.Fields = {
          'LinkFilename' : { 'View': renderLinkFilename }
      };


      SPClientTemplates.TemplateManager.RegisterTemplateOverrides(ctxView);
    } 
    ExecuteOrDelayUntilScriptLoaded(registerRenderer, 'clienttemplates.js');

})();

How to apply changes

Set the JSLink property of a List View Web Part:

  • Upload JavaScript template file into Site Assets library
  • Edit the page, then edit the web part. Under Advanced specify JavaScript template file location in JS Link property

Upvotes: 3

Related Questions