Editor Upload - Append row data (i.e. file_id) with ajaxData
Editor Upload - Append row data (i.e. file_id) with ajaxData
deesen
Posts: 9Questions: 1Answers: 1
Hi, I have my own image-manager class in PHP and everything is working fine. Except that I want to send the actual "file_id" when uploading a file. I already found out how to add data, but I don´t know how to access the actual edited row´s data from inside "ajaxData" to pass the actual "file_id" (in below example "data.image_id") :
{
label: 'Image:',
name: 'image_id',
type:'upload',
ajax:'/?com=product§ion=attribute&action=edit&id=2',
ajaxData: function ( d ) {
d.append( 'ajax', 'b149e4ff7305f4ffe58a44841630eb80' );
d.append( 'old_id', data.image_id );
}
}
Is it possible? Thanks!
This discussion has been closed.
Answers
Of course it is... with
https://datatables.net/reference/api/row().index()
https://datatables.net/reference/api/row().data()
My solution:
I am using inline-editing for text and bubble-edit for file-uploads to have error-messages, so I already catch click-events, which is filling now also
ajaxRowId
, the actual clicked row´s index.There is no way to access the row's data from there. Consider for example when you are creating a new row. It doesn't have an id until it is submitted to the server which generates one.
Allan
Sorry that I cannot offer access to a live-version (localhost), but it definetly works for my purposes. I am using localStorage like in my last question: https://datatables.net/forums/discussion/35994/editor-upload-how-to-add-files-array-without-initial-ajax-request
I also added the files-object to ajaxData, so its possible to add multiple uploads to a table without changing any SQL-data, except the added images of course. I use perceptional hash so when an image is a dublicate or filename already existing, the old ID will be returned with an error-msg.
This way on server-side its very simple to update the files-array with all the new added IDs and send it back to client.
If interested, my full code without all my additional fields looks like