Example of files array
Example of files array
We wanted to know if there is a sample for how the "files" : []
array is sent from server to client to populate DataTables.
Here is what we are trying to achieve.
Step 1
- We load our page for the first time. The table is blank as expected.
- We click "New" to add a new row to the DataTables using DataTables Editor plugin.
- We fill in the required information which includes an image, so we upload the image and click "Create" button.
- The row is added and it displays fine in the DataTables.
- if we click on "Edit" button before refreshing the page, the "Editor" shows the data and the image just fine.
- We close the browser or refresh the page.
Step 2
- Our server retrieves the dat, constructs the required AJAX data and sends it to the browser
- DataTables displays the row we added earlier.
- We click on "Edit" for the row. Here we expect that the image we uploaded earlier will be displayed.
** NOTE ** - our table does not have a column for the image. The field is only available in the "Editor"
Our question: how should we construct the AJAX to send in the image (file) information.
{
"data": [
{
"DT_RowId": "row_1",
"first_name": "Quynn",
"last_name": "Contreras",
"phone": "1-971-977-4681",
"city": "Slidell",
"image": null
},
{
"DT_RowId": "row_2",
"first_name": "Kaitlin",
"last_name": "Smith",
"phone": "1-436-523-6103",
"city": "Orlando",
"image": null
}
],
"options": [],
"files": []
}
The second last line in the code snippet above shows "files" : []
. However we were unable to find documentation/syntax as to how this array is to be constructed.
Could you please point us in that direction?
Additional Info : we are not using DataTables server side code as we get the data from an API. Our server manipulates the data to conform with the AJAX that DataTables expects.
This question has an accepted answers - jump to answer
Answers
Hi,
This page contains a suitable example. Upload a couple of images and then reload the page and click the "Ajax load" tab below the table or use the browser's network inspector to see the loaded JSON.
Let me know if you run into any issues with that.
Allan
Allan, thank you so much for a prompt response. I will try that and let you know if that works.
It did not work for the following reason. I'm getting the following error. Can you please help?
No data available in table
Originally, I was sending AJAX data to Datatable as shown below. This works fine.
With the example you showed, the new AJAX data comes up as follows
Here is the Javascript
Allan, I also ran the debugger and it shows no error. I can "Upload configuration data" if it helps
I found a solution. Here is what I did
dataSrc
function I returnreturn json.data;
instead of justreturn json;
.Thank you so much for your help.