Having an issue returning file uploads
Having an issue returning file uploads
nuggetap3
Posts: 24Questions: 5Answers: 2
When I attach a file to on of the rows in my table it returns a link to the item. If it is a pdf, it returns a straight hyperlink. If it is an image type, it returns a link in the form of a thumbnail. However, I am having an issue when there is no attachment for that row. If there is no attachment, then it should simply say no file. However, when the row is created it is not returned to the datatable.
Here is my code
"data": "attachments",
render: function (Id) {
var ext = traveleditor.file('expenseAttachment', Id).webPath.toLowerCase();
var ext1 = ext.split(".").pop();
if (ext1 == "pdf") {
//return '<center> <i class ="fas fa-file-pdf" style="font-size: 2.73em;"' + traveleditor.file('expenseAttachment', Id).webPath + '"</i></center>';
return '<a href ="' + traveleditor.file('expenseAttachment', Id).webPath + '" target=_blank><i class =" glyphicon glyphicon-file" style="font-size: 1em; "</i>' + traveleditor.file('expenseAttachment', Id).filename + '</center></a>';
}
else if ((ext1 == "png") || (ext1 == "jpg") || (ext1 == "gif")) {
return '<a href ="' + traveleditor.file('expenseAttachment', Id).webPath + '" target=_blank><img width="100px" src="' + traveleditor.file('expenseAttachment', Id).webPath + '"/></a>';
}
else {
return "No File";
}
This question has accepted answers - jump to:
This discussion has been closed.
Answers
This may be a typo in your post, but your render() function is lacking a closing brace ( } ).
I'd probably suggest having:
at the top of your function. At the moment the code is assuming that even if there is no id (which I don't think there will be if there is no file) it can still get information about that file (which doesn't exist).
Allan
Thanks Allan, we were able to get it working.
```
"data": "attachments",
render: function (Id) {