Trying to feed a Datatables table a set of json data straight from Google Sheet I got this kind of error in the first place:
DataTables warning: table id=example - Requested unknown parameter 'name' for row 0, column 0. For more information about this error, please see http://datatables.net/tn/4
Here is my json vs the one provided in their example which of course has a different format
{
"range": "json!A1:Y1000",
"majorDimension": "ROWS",
"values": [
[
"name",
"position",
"salary",
"start_date",
"office",
"extn"
],
[
"Unity Butler",
"prova",
"$85,675",
"2009/12/09",
"San Francisco",
"5384"
]
]
}
{
"data": [
{
"id": "1",
"name": "Tiger Nixon",
"position": "System Architect",
"salary": "$320,800",
"start_date": "2011/04/25",
"office": "Edinburgh",
"extn": "5421"
},
{
"id": "2",
"name": "Garrett Winters",
"position": "Accountant",
"salary": "$170,750",
"start_date": "2011/07/25",
"office": "Tokyo",
"extn": "8422"
},
{...}
]
}
I understood different formats need different treatments and I was curious to know how. The answer provided by @andrewjames which I have accepted explains both the nature of the different formats and how to treat them.
Basically all it took was removing the "columns" parameter from the ajax option, as you can see from this jsfiddle where you can find the complete working code (along with libraries as well).
UPDATE: supplementary task
Now, suppose you want to arrange some extra information into a set of toggle hide-show child rows.
As long as the data format respects the original one provided by the example I can easily do that: I can even grab data from a mysql db via a .php file and arrange it into json! jsfiddle
<?php
$con=mysqli_connect("","","","");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$out = array();
if ($result = mysqli_query($con, "SELECT * FROM your_table")) {
$out = $result->fetch_all(MYSQLI_ASSOC);
}
echo "{ \"data\": ", json_encode( $out ), "}";
mysqli_close($con);
?>
Problems start when I try to pull data from my usual GSheet-fed json array: how can I conjugate child rows toggle capabilities and a GSheet typically formatted json file ?