Pass additional meta data to javascript array
Pass additional meta data to javascript array
alzambo
Posts: 38Questions: 17Answers: 1
Hi,
I need to pass some additional data to datatable through a javascript array.
This would be my data array to be passed to dt:
datiTabella = array(
'dati' => array(
0 => array(
'id' => '1'
),
1 => array(
'id' => '2'
)
),
'schema' => array(
0 => array(
'nomeCampo' => 'id',
'relazione' => 'incarico.idAssicurato'
)
)
);
'dati' contains database data
'schema' contains database fields metadata, to be used in a function
In every column i need to access both 'dati' (to be displayed) and 'schema' to be used in a function, but how to access that keys?
"data": datiTabella,
"columns": [
{
// THIS IS THE 'ACTION' COLUMN: it contains links related to the data row and that links should depend on data in 'schema' key
"data": null,
"render": function(data, type, row, meta) {
// HERE I NEED TO ACCESS 'schema' key to output functional buttons
}
},
{
"data": // HERE I NEED TO ACCESS 'dati' key
}
]
Could someone help?
Thank you
Alex
This discussion has been closed.
Answers
...up...
Try adding
console.log(row);
into your rendering function to see what data is available in the row.I don't know what the demo SSP class will do with the input configuration above - perhaps you've modified it to allow for that and return the required JSON?
Allan
Hi Allan,
it doesn't display anything (not even errors) on render function.
I need to precise that my table is client side, with data array populated in php and converted to js array with
This is my js
and this is html
Thank you for helping me...
Alex
Can you show me what
datiTabella
contains then please?Thanks,
Allan
Hi Allan,
here it is:
Thanks
Alex
Hi Alex,
Which array is the one you want to show in the DataTable? You could use
data: datiTabella.schema
if you want to show the schema array for example.Each array element is a row in the table.
Allan
Hi Allan,
datiTabella.schema
would contain just one 'trigger' (basically the related field name). I need it in a function for output an additional link (to perform a db query) in every row. So it's logically related to the column and not to every row.So I need to use both arrays:
datiTabella.dati
onid
column anddatiTabella.schema
onAzioni
column.Would it be possible?