Data source - Child row Table
Data source - Child row Table

Hello,
I have an API from a server which returns this code format:
{
"status":"success",
"time(sql)":0,
"count":2,
"list":[
{
"number":"ITF00198325",
"type":"II",
"requestor":"fhaff",
"reqdate":"2019-06-18 09:59:04",
"efr":"fhaff",
"status":"End",
"order":"1100070645",
"country":"FR",
"city":"Sophia Antipolis",
"zip":"06560",
"address":"2740 route des Cretes",
"comments":"",
"item":[
{
"sku":"FSA-3000D",
"desc":"Advanced Threat Protection System - 4 x GE RJ45, 2 x GE SFP slots, 2 x 10GbE SFP+ Slots, redundant PSU, 28 VMs with Win7 and (3) MS Office License included",
"qty":"1",
"serial":"FSA3KD3R16000260"
}
]
},
{
"number":"ITF00214345",
"type":"II",
"requestor":"fhaff",
"reqdate":"2019-09-30 01:50:45",
"efr":"fhaff",
"status":"End",
"order":"1100082924",
"country":"FR",
"city":"Valbonne",
"zip":"06560",
"address":"2740 route des cretes",
"comments":"",
"item":[
{
"sku":"FWF-60E-DSL",
"desc":"9 x GE RJ45 ports (including 7 x Internal Ports, 1 x WAN Ports, 1 x DMZ Port), Internal ADSL2/2+ and VDSL2 (Annex A/M) modem, Wireless (802.11ac)",
"qty":"1",
"serial":"FW60EVTK19000051"
}
]
}
]
}
I would like to build a DataTable with childrow:
Table: (for Each element from list)
list.number | list.type | list.status | list.requestor | list.order | list.reqdate | list.address | list.city | list.zip | list.country
Child row (for each element from list.item)
List.item.sku | List.item.qty | List.item.serial
Really important: I have to update this table from a form and a button (already created)
Can somebody help me with the data management ?
Thnaks !
Edited by Colin - Syntax highlighting and JSON formatting. Details on how to highlight code using markdown can be found in this guide.
Replies
This example will show you how to use ajax objects. You'll need to specify
ajax.dataSrc
to belist
, as that object contains your data.Then, for child rows, you can get the full data for the row with
row().data()
which you can then display as a child row.Colin
Thanks for your help !
For an example, considering my html table as:
My variable "data" as:
So, I have to create my table like this ?
As Colin mentioned you need to use
ajax.dataSrc
. Then usecolumns.data
. Something like this:Kevin
Ok kthorngren thanks I understood for the structure.
However I'm really not used to work with Ajax.
Here is my query to my API:
How can I integrate it in the DataTables construction ?
Thanks
You can initialize your Datatables within the $.post callback. Like this:
Instead of using
ajax
use thedata
option to load the table data.Kevin
Thanks Kevin, it works !
I did it in order to do a new search from my form and "update" the table:
I will investigate now for drawing the child rows ^^
Thanks again
Looks good!
Kevin
Hi Kevin.
Yesterday all was working perfectly.
However for security reasons, the server changer JSON to JSONP.
How can I use it to have the same result ?
Thanks in advance
I found it by myself, thanks for your help.
If it can help somebody, here is my DataTables creation:
And the JSONP structure: