JSON Array without associative keys
JSON Array without associative keys
My json array is a 2 dimensional array.
$array[row][column] where the first [row] is a table header row.
I can build a table using for loops, but that is very problematically to use the row-details function.
I pass the json data var dataSet = <?php print_r($text['post_content']);?>;
and data: dataSet in the table definition.
But than I dont know how to use it in the function
function format ( d ) {
// `d` is the original data object for the row
return '<table cellpadding="5" cellspacing="0" border="0" style="padding-left:50px;">'+
'<tr>'+
'<td>Full name:</td>'+
'<td>'+d.name+'</td>'+
'</tr>'+
'<tr>'+
'<td>Extension number:</td>'+
'<td>'+d.extn+'</td>'+
'</tr>'+
'<tr>'+
'<td>Extra info:</td>'+
'<td>And any further details here (images etc)...</td>'+
'</tr>'+
'</table>';
}
I cannot put +d.1+ for the first column, that is inconsistent
Could you help me?
Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
This question has accepted answers - jump to:
Answers
I am not sure that I get what you are asking so I assumed that you are trying to create a table from a double dimension table. So here is my solution:
You can see it work here: http://live.datatables.net/yuhutuni/1/edit
Without the syntax highlighting (which I've now added) there was a lot of context missing in the example.
In the row details function you would use array notation to access information from an array of data - e.g.
d[0]
.Allan
Thank you very much for your responce!
I will try your sugestion now.
I tried to combine your method and the https://datatables.net/examples/api/row_details.html
where I've put d[0]
Could you check my code and tell me what i am doing wrong?
http://live.datatables.net/madumexe/1/edit
Thank you very much
http://live.datatables.net/madumexe/2/edit
You didn't have anything enabled to show / hide the details row. I've put the event handler on the whole row, but you can modify that as you need.
Allan
Tank you vary much for your quick answer.
I'm noob in JS thats I ask you some more questions:
In the code
http://live.datatables.net/roxopatu/1/edit
I try to push headers and fileds in childer rows. Could you tell me what I am doing wrong?
And how can I define "className": 'details-control' in columns option of table definition, if there is already columns: cols ?
Thank you very much in advance.
BR Maks
This is adding data to the row's data array! You want to output HTML from the
format
function - not modify the original array.The
columns
array needs to have exactly the same number as entries as the number of columns that will be shown. In the above you only define a single column, so that won't work I'm afraid. You need to define something for each column, even if it isnull
(i.e. no extra options).Allan