How to view an uploaded image, like in editor?
How to view an uploaded image, like in editor?
Okay this is a simple one I think, but I have not been able to find any forum posts that ask this.
Quick background, so you understand what I am trying to do. I use file upload to upload scanned letters. The file upload piece works fine, and on the database table, it renders fine (see below):
var table = $('#correspondenceTable').DataTable( {
// lengthChange: false,
pageLength : 5,
lengthMenu: [[5, 10, 20, -1], [5, 10, 20, 'Todos']],
ajax: "ajaxCorrespondence.php",
columns: [
{data: "scanned_mail.postmark_date" },
{data: "scanned_mail.priority" },
{data: "scanned_mail.category" },
{data: "scanned_mail.attention" },
{data: "scanned_mail.chapter", visible: false},
{data: "scanned_mail.cr_id" },
{data: "scanned_mail.campaign" },
{data: "scanned_mail.pe_choice1", visible: false, searchable: false },
{data: "scanned_mail.pe_choice2", visible: false, searchable: false },
{data: "scanned_mail.notes", visible: false, searchable: false },
{
data: "scanned_mail.image",
render: function ( file_id ) {
return file_id ?
'<img src="'+editor2.file( 'scanned_files', file_id ).web_path+'" width="45" height="45"/>' :
null;
},
searchable: false,
defaultContent: "No scan",
title: "Letter"
}
],
select: true
} );
When a user views it, and selects the record, they will press a button to view the letter in full size. I am using a separate editor instance for this, which also opens fine (see below):
editor3 = new $.fn.dataTable.Editor( {
ajax: "ajaxCorrespondence.php",
table: "#correspondenceTable",
display: 'bootstrap',
fields: [ {
label: "Scanned Letter:",
name: "scanned_mail.image",
type: "upload",
display: function ( file_id ) {
return '<img src="'+editor2.file( 'scanned_files', file_id ).web_path+'"/>';
},
clearText: "Clear",
noImageText: 'No Scan'
}
]
} );
From this editor, however I DO NOT want the user to edit or change the uploaded file (link), and see it full size. This user will be actually reading the scanned letter. So to reiterate, nothing is broken, and everything is currently working as designed, I just want to add this ability. Thoughts and suggestions? Thanks so much.
This question has accepted answers - jump to:
Answers
Do you mean you want the upload field to be read only?
field().disable()
will do that.Or do you mean you just want the file to be shown in the modal, but no editing control for it at all? If so, use this plug-in which will draw out the value (you'd need to modify it a little to include the
img
element.Allan
Yes, the file shown in the modal with no editing control. I installed the plug in, and it's only returning the file_id number no matter what variation I try.
Thing is, I definitely needed this plug-in earlier, and I will make good use of it in the rest of my project so thanks. I'm going to mark this answered, even though it hasn't solved my problem as of yet. If you can post a working example, that would be helpful. Otherwise thanks for the direction, I know this will work somehow, when I figure it out I will post it for the next person.
Ok, this may be a possible fix, but I need a little help.
I found this post https://datatables.net/forums/discussion/71125/showing-an-image-in-an-image-viewer. And it does exactly what I need.
However the render function is not passing over the path, so the viewer works, but has no image to link to. See here:
alternatively, this wouldn't work either: It shows the image id of 5
Thoughts?
There is no
render
ordisplay
option for that plug-in. You'd need to update theset
function in it to create theimg
tag based on the file information. You can usethis.file('scanned_files', val);
to get the file information (that just gives you thefile()
method.Allan
Ahh, Thanks!
Just so anyone else tries to do this, modifying the set function in editor.display.js from
to this
note: scanned_files is my table name to store file info. Like files in the editor examples.
Will allow you to display the the file image, in say a separate editor instance like this
that users can activate with a button like this:
Awesome, This really beats taking the value and image paths from the select, loading and rendering into a separate bootstrap modal. Which was what I thought I'd have to do.
A nice option for that plug-in might be to add a
render
option to it. It isn't something I've encountered a need for before, but now that I've seen your question here, I'm surprised I haven't! I'll look into that.Allan
Also like I said before, I really love this plugin, there are so many frontend uses. So I actually kept
_fieldTypes.display = {
as is, and added_fieldTypes.displayimage = {
with the image changes, that way I can use the plugin for images withtype: "displayimage"
andtype: "display"
as you originally designed.