json format for DataTables
json format for DataTables
abramhum
Posts: 5Questions: 3Answers: 0
Hi:
deal all, I have a problem about the json format for DataTable.
The following is the txt which the DataTables needed:
{
"data": [
{
"name": "Tiger Nixon",
"position": "System Architect",
"salary": "$320,800",
"start_date": "2011\/04\/25",
"office": "Edinburgh",
"extn": "5421"
},
{
"name": "Garrett Winters",
"position": "Accountant",
"salary": "$170,750",
"start_date": "2011\/07\/25",
"office": "Tokyo",
"extn": "8422"
}
]
}
And the code snippet is as below:
$('#example').DataTable({
"ajax": "simple.txt",
"columns": [
{ "data": "name" },
{ "data": "position" },
{ "data": "office" },
{ "data": "extn" },
{ "data": "start_date" },
{ "data": "salary" }
]
});
And the result is I need to add the '{"data:"' and ' }" to my json data each time,
why not just use the txt without the data tag, like following:
[
{
"name": "Tiger Nixon",
"position": "System Architect",
"salary": "$320,800",
"start_date": "2011\/04\/25",
"office": "Edinburgh",
"extn": "5421"
},
{
"name": "Garrett Winters",
"position": "Accountant",
"salary": "$170,750",
"start_date": "2011\/07\/25",
"office": "Tokyo",
"extn": "8422"
}
]
Is that possible to do that? Thanks a lot.
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
You can use
ajax.dataSrc
. Take a look at the second example.Kevin
Dear Kevin:
It seems not working. I have tried following:
And the simple.txt is as below
It can not read the correct data.
Is there anything I need to modify, thanks a lot.
That looks absolutely spot on to me. Can you link to a test case showing the issue please?
This example shows it working.
Allan
Thanks a lot.