Display attachments in list view

25/04/2018 17:22
here is content of JSLink file, attached directly to field in code behind via JSLink property
 
This code displays links to attachments directly in list view instead of clip icon and also changes clip column header to another title: Certifikat. Attachments are open in the other tab.
 
(function () {
    var ctx = {};
    ctx.Templates = {};
    ctx.Templates.Fields = {
        'Attachments': {
            'View': AttachmentsFiledTemplate
        },
    };
    ctx.OnPostRender = showAttachmentFieldTitle;
    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(ctx);
})();
 
function AttachmentsFiledTemplate(ctx) {
    var itemId = ctx.CurrentItem.ID;
    var listName = ctx.ListTitle;
    return getAttachments(listName, itemId);
}
 
function getAttachments(listName, itemId) {
 
    var url = _spPageContextInfo.webAbsoluteUrl;
    var requestUri = url + "/_api/web/lists/getbytitle('" + listName + "')/items(" + itemId + ")/AttachmentFiles";
    var str = "";
    // execute AJAX request
    $.ajax({
        url: requestUri,
        type: "GET",
        headers: { "ACCEPT": "application/json;odata=verbose" },
        async: false,
        success: function (data) {
            for (var i = 0; i < data.d.results.length; i++) {
                str += "<a href='" + data.d.results[i].ServerRelativeUrl + "'  target='_blank'>" + data.d.results[i].FileName + "</a>";
                if (i != data.d.results.length - 1) {
                    str += "<br/>";
                }
            }
        },
        error: function (err) {
            //alert(err);
        }
    });
    return str;
}
 
function showAttachmentFieldTitle(ctx) {
$('#diidSort0Attachments').html('<span>Certifik√°t</span>');
    
}