0

I'm using SharePoint 2013. When using a custom list an option available is a View Item column that allows the user to view the item details. But I don't see the same option for a document library.

Is there anyway I can have the view item option as in a custom list in a document library without having to use the ribbon to view the item properties?

1

You want to view properties of a document by clicking a column directly. By default, SharePoint uses DispForm.aspx (a display form) to display the item properties. We need to generate the link and display the link in one column.

There are two methods:

Method 1: Get the ID of the document via the workflow and use calculated column to combine text and render it as a hyperlink.

Create a workflow and start it automatically when an item is created. Set a field value (such as “GetId”) to the item Id using the workflow. Create a calculated column with the following formula. Output the data with “Number” or “Currency” type for this calculated column, it will render the field into HTML.

"<a href='sp/sites/team/doc1/Forms/DispForm.aspx?ID="&[GetId]&"'>view properties</a>"

Method 2: Use JavaScript to generate the path and overwrite a column value and render it as a link.

<script type="text/javascript">
function displayLayover(url) {
 var options = SP.UI.$create_DialogOptions();
 options.url = url;
 SP.UI.ModalDialog.showModalDialog(options); 
 }

(function () {
    var overrideNameField = {}; 
    overrideNameField.Templates = {};
    // This action will edit the “Title” field. You can change the “Title” to another custom field.
    overrideNameField.Templates.Fields = {
        "Title": { "View": overrideNameFieldTemplate }        
    };    
    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideNameField);
})();

function overrideNameFieldTemplate(ctx) { 
    var itemID = ctx.CurrentItem.ID;
    //It get the item title
    var content = ctx.CurrentItem["Title"];
    // You can also set a field value as you want.
    //var content = "edit its properties";
    // here the url should be of your document library. In my case it was a library named "Doc2".
    var url = _spPageContextInfo.webAbsoluteUrl +"/Doc2/";    
    return "<a href='javascript:displayLayover(&quot;" + url+ "Forms/DispForm.aspx?ID="+itemID+"&IsDlg=1&quot;)'>" + content + "</a>"; 
}
</script>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.