looping throuhcolumns?
looping throuhcolumns?
I am new to datatables and have json data like this:
[
0: {
Customers [
{
Name: "Harry",
Code: 1234
},
{
Name: "James",
Code: 5678
}
]
},
1: {
Customers [
{
Name: "Ben",
Code: 7890
},
{
Name: "karl",
Code: 4457
}
]
},
....
]
I need to be able to display this data but I don't necessarily know how many entries in the array there are
so far I have this:
$("#customers-table").DataTable({
type: "GET",
ajax: {
url: "myurl/something",
dataSrc: ""
},
"columns": [
{
data: "Customers.0",
render: function (value, type, row) {
return value.Name;
}
},
{ data: "Name" }
]
});
I need to make "Customers.0" increment somehow, is this possible?
This question has an accepted answers - jump to answer
Answers
No.
But you could use
ajax.dataSrc
as a function to loop through the ajax response and create something more like this:There is a function example in the docs. This can be returned in your function then you just need this in your
columns.data
config:Kevin