4

enter image description here

Ok, when I do as suggested by @users1100

This is the result I get, the column names goes away totally, and Title is still not acting as an url/linked to document.

  • How you deployed JSLink. Here is a example how to do it code.msdn.microsoft.com/office/… – P S Sep 29 '15 at 14:30
  • I deployed it into documents, and then refered to it in the Edit web part - JSLink. Whenever i try this, the pages ends up looking like the Picture above. Ive tried alot of scripts now, but dont seem to know what im doing wrong. I want the the title to behave as a link, where it extracts the title, not the name of the document. I just want to make a change on this list. – Alice Sep 30 '15 at 11:06
  • @p s forgot to tag you – Alice Sep 30 '15 at 11:28
3

You need to apply JSLink for the view.

Below is the code which you can add it to JSLink:

(function () {
    var overrideNameField = {}; 
    overrideNameField.Templates = {};
    // Title field will rediect to the last major version of the document.
    overrideNameField.Templates.Fields = {
        "Title": { "View": overrideNameFieldTemplate }        
    };    
    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideNameField);

})();
function overrideNameFieldTemplate(ctx) { 
    var title = ctx.CurrentItem.Title;
    var fileRef = ctx.CurrentItem["FileRef"];
    var fileLeafRef = ctx.CurrentItem["FileLeafRef"];

    // here the url should be of your document library. In my case it was Pages library.
    var url = _spPageContextInfo.webAbsoluteUrl + "/Pages/" + fileLeafRef;    
    if (title) {
        return "<a href='"+ url + "'>"+ title + "</a>"; 
    }
    else {
        return "<a href='" + fileRef + "'>" + fileLeafRef + "</a>";
    }
}

Hope this helps.!

0

You cannot achieve this OOB, because if you go to EditView page from list settings you will not find any options like Title(Linked to Document) but just Title.

Also do not choose to edit webpart, this is not the best practice. And instead of solving your problem will become part of your problem in maintaining it.

JSLink is the best possible option to choose. Because its a JavaScript file which can be source controlled, and easily deployed on the Production environment.

  1. To set JSLink to your view, refer Setting JSLink SharePoint online
  2. Read about JSLink at Using JSLink to change the UI of a SharePoint list/view by Chris O'Brien
0

Another solution would be to do this using workflow. Create a hyperlink column and update it from the workflow.

Workflow steps:

Create a workflow and build a dynamic string in the format {url}, {description}. (Should be a space after ,). You can get the url by using the Encoded Absolute URL property of the current item. For description, you can get the current item title. Update the hyperlink column using the string created above ({url}, {description}) and show in view.

This won't update the Name field directly but you'll get what you want. If you are not well versed in JS, this would be worth looking at.

0

Sorry, I have this weird mental condition where I rewrite JavaScript because it just reads better and processes faster.

This

function overrideNameFieldTemplate(ctx) {
    var title = ctx.CurrentItem.Title;
    var fileRef = ctx.CurrentItem["FileRef"];
    var fileLeafRef = ctx.CurrentItem["FileLeafRef"];

    // here the url should be of your document library. In my case it was Pages library.
    var url = _spPageContextInfo.webAbsoluteUrl + "/Pages/" + fileLeafRef;
    if (title) {
        return "<a href='" + url + "'>" + title + "</a>";
    } else {
        return "<a href='" + fileRef + "'>" + fileLeafRef + "</a>";
    }
}

Can be rewritten to:

function overrideNameFieldTemplate(ctx, CurrentFieldSchema, CurrentItem, ListSchema) {
    var url = CurrentItem.FileRef,
        title = CurrentItem.Title;
    if (title) {
        url = _spPageContextInfo.webAbsoluteUrl + "/Pages/" + CurrentItem.FileLeafRef;
    } else {
        title = CurrentItem.FileLeafRef;
    }
    return String.format("<a href='{0}'>{1}</a>", url, title);
}
0

Faster way

context.Templates.Fields = {
       'Title': { 'View' : '<a href="<#=ctx.CurrentItem.FileRef#>"><#=ctx.CurrentItem.Title#></a>' } 
    };

SPClientTemplates.TemplateManager.RegisterTemplateOverrides(
    context
);

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.