Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 82030

In order to work, why does the AJAX array need to be called 'data" in the "Child rows example"?

$
0
0

I would like to load data into a DataTable using "Child rows" attached to a parent table from a MongoDB data source. MongoDb allows for embedded documents as arrays and/or JSON objects. Some of that data will have the same structure as the sample AJAX used in the "Child rows" example page, with the exception that the name "data" might be "subcontractor" or "manager" instead . The following shows the start of the example AJAX with the name "data":

"data": [
{
"id": "1",
"name": "Tiger Nixon",
"position": "System Architect",
"salary": "$320,800",
"start_date": "2011/04/25",
"office": "Edinburgh",
"extn": "5421"
}

I have no problems using the example JavaScript and AJAX data as long I don't modify the spelling for the name "data" in the source data. When I tried changing "data" to "subcontractor" or "data2" the DataTable wouldn't work. I tried modifying the JavaScript below by changing any reference to "data" to "subcontractor" or "data2" with no results. What do I need to change in the sample JavaScript below to use a different name than "data" in my source JSON?

$(document).ready(function() {
var table = $('#example').DataTable( {
"ajax": "../ajax/data/objects.txt",
"columns": [
{
"className": 'details-control',
"orderable": false,
"data": null,
"defaultContent": ''
},
{ "data": "name" },
{ "data": "position" },
{ "data": "office" },
{ "data": "salary" }
],
"order": [[1, 'asc']]
} );

This is the link to the"Child rows" sample page:

https://datatables.net/examples/api/row_details.html


Viewing all articles
Browse latest Browse all 82030

Trending Articles