0
I’m having trouble generating a dynamically popular JSON message a Datatable.
When I do it this way it works:
var dataSet = [
[ “1”, “01/10/2018”, “200,00” ],
[ “2”, “01/11/2018”, “250,00” ],
[ “3”, “01/12/2018”, “350,00” ]
];
$(’#teste’).DataTable({
//paging: false,
//searching: false,
retrieve: true,
destroy: true,
data: dataSet,
columns: [
{ title: “id” },
{ title: “Data” },
{ title: “Valor” }
]
});
When I try to generate dynamically, it doesn’t work.
for (var i = 0; i < dados.length - 1; i++){
p = “[ “” + (i+1) + “”,”;
d = “”" + dados[i] + “”,";
v = “”" + vlr + “” ]";
msgJson = msgJson + p + d + v + “,”;
}
dataSet = msgJson.substr(0,msgJson.length-1);
Generated msgJson message:
[ “1”,“11/10/2018”,“30” ],[ “2”,“11/11/2018”,“30” ],[ “3”,“11/12/2018”,“30” ]
Some light?
I think the syntax like this
p = "["" + (i+1)...
can cause problem. Write distinguishing double quotes and simple like thisp = '[""+ (i+1)...
– LeAndrade