Upload - icons insteed of images
Upload - icons insteed of images
Hello Allan and everyoneelse,
I tried to upload PDF files with the upload many examples (https://editor.datatables.net/examples/advanced/upload-many.html) and insteed of showing the images (<img src=) I want to show icons with a link to the files.
But this doesn't work with FireFox:
fields: [ {
label: "First name:",
name: "users.first_name"
}, {
label: "Last name:",
name: "users.last_name"
}, {
label: "Phone #:",
name: "users.phone"
}, {
label: "Site:",
name: "users.site",
type: "select",
placeholder: "Select a location"
}, {
label: "Images:",
name: "files[].id",
type: "uploadMany",
display: function ( fileId, counter ) {
return '<a href="'+editor.file( 'files', fileId ).web_path+'"><img src="/intern/images/file_types/pdf.png"/></a>';
// return '<img src="'+editor.file( 'files', fileId ).web_path+'"/>';
},
noFileText: 'No images'
}
And insteed of showing "1 image(s)" or "2 image(s)" I want to show an icon per file.
How can I add the url (e.g. web_path) into the link (<a href=)?
columns: [
{ data: 'users.first_name' },
{ data: 'users.last_name' },
{ data: 'users.phone' },
{ data: 'sites.name' },
{
data: "files",
render: function ( d ) {
return d.length ?
'<a href=""><img src="/intern/images/file_types/pdf.png"/ width="32" height="32"></a>' :
'No image';
return d.length ?
d.length+' image(s)' :
'No image';
},
title: "Image"
}
],
A complete example of my try can be found here -> http://wechselstube.host4free.de/editor/
Thanks for any help
pib
This question has an accepted answers - jump to answer
Answers
The problem with both parts is that your
d
parameter in the DataTable is an array - you need to use afor
loop (or any other type of loop you want) to spin over the array and generate the HTML you want to output.Allan
Thanks foryour advice.
I guess I figured out how to read out this response:
But how do I get the files information into the render function? I mean the filename and url.
Using
editor.file(...)
was correct, you just need to pass in an integer at a time, not the whole array - e.g.d[i]
.Allan
I need the whole array, because there can be more than one file per user ;-)
Unfortunately I have two issues with the editor.file. In usersTable and in usersEditor I don't get any result:
Can you also please take a look at http://wechselstube.host4free.de/editor/? There I uploaded the whole example.
Thanks
pib
If you have a look in your browser's console you'll see an error about "editor is not defined". That's because while you are using
editor.file(...)
there is noeditor
variable. Instead you havesiteEditor
andusersEditor
variables. If you update your code to refer to the correct variable that should do it.Allan
With usersEditor it works as expected:
Thank you very much again :-)
Pib