About file upload for standalone editor
About file upload for standalone editor
yu yen kan
Posts: 65Questions: 31Answers: 0
json response from server when upload file
{"data":[],"files":{"gallery":{"182":{"id":182,"filename":"abc","filesize":10000,"path":"...."}}},"upload":{"id":182}}
render editor field
name: "itemGallery[].id",
type: "uploadMany",
display: function (file_id, counter) {
return '<img src="' + editor.file('gallery', file_id).path + '"/>';
},
I get javascript error
Unknown file table name: gallery
This discussion has been closed.
Answers
Hi,
What version of Editor are you using please? That looks like it should actually work with 1.6.1.
If you are already using 1.6.1, could you give me a link to the page showing the issue so I can debug it please?
Thanks,
Allan
yes, it is 1.6.1, I cant setup on http://live.datatables.net/ and it is on local hosting
Why not?
http://live.datatables.net/cusuzoyu/1/edit
server code
Ah - I think I know what it is. Do you get this error when you open the Editor view to edit the values? Or does it happen when you upload the file?
My guess is the former, and that is happening because with a DataTable, the files object can be populated from the DataTables Ajax request. If you are using a standalone Editor there is no way for Editor to know about the files that you have uploaded already.
What you would need to do is add the file information to the
$.fn.dataTable.Editor.files
object.This is what Editor does:
Allan
with $.extend( Editor.files[ table ], files ), editor.file('files', file_id) will still get error of table name 'files', I tried to use
and it work
What is your
files
variable? It would need be an object that contains agalleries
object that has the information about the files.Allan
yes, it is object
And does it contain a
galleries
property? If you could show me the result ofJSON.stingify( files )
that would be useful.Allan
the json string returned from server and editor field declaration is shown in on the question of this discussion
If you are referring to this:
I don't see a "galleries" property, which is what Allan has been asking you.
That's after an edit. I'm interested in the value of your variable when that code runs - i.e. before the Ajax request for the edit is made.
Allan
this?
"{"action":"upload","uploadField":"item_gallery","upload":{}}"
or
I might be understanding the issue now:
Here
editor
is your Editor instance presumably. However, it should be getting assigned to$.fn.dataTable.Editor
which is what theEditor
variable in my code above is. I should have made that clear at the start.Allan
work fine for me by edit in below 2 places(support uploadMany):
edit in dataTables.editor.js:4101
in javascript:
in PHP server i use the simple way: