Created
July 24, 2018 20:25
-
-
Save nchambe/51e5cc6c5b03623bf4d979ea9d72c38e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.3.1.min.js"></script> | |
<script type="text/javascript"> | |
(function () { | |
var attachmentsFiledContext = {}; | |
attachmentsFiledContext.Templates = {}; | |
attachmentsFiledContext.Templates.Fields = { | |
"Attachments": { "View": AttachmentsFiledTemplate } | |
}; | |
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(attachmentsFiledContext); | |
})(); | |
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 = ""; | |
$.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 + "'>" + data.d.results[i].FileName + "</a>"; | |
if (i != data.d.results.length - 1) { | |
str += "<br/>"; | |
} | |
} | |
}, | |
error: function (err) { | |
} | |
}); | |
return str; | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment