Loading Data from txt not working

Loading Data from txt not working

[Deleted User][Deleted User] Posts: 0Questions: 6Answers: 0
edited December 2019 in Free community support

I have a txt named entries.txt looking like this:

[{
"id": "1",
"name": "Tiger Nixon",
"position": "System Architect",
"salary": "$320,800",
"start_date": "2011/04/25",
"office": "Edinburgh",
"extn": "5421"
},
{
"id": "2",
"name": "Garrett Winters",
"position": "Accountant",
"salary": "$170,750",
"start_date": "2011/07/25",
"office": "Tokyo",
"extn": "8422"
}
]

My code is looking like this:

var table = $('#example').DataTable( {
"ajax": "./entries.txt",
"columns": [
{
"className": 'details-control',
"orderable": false,
dataSrc: ''
"defaultContent": ''
},
{ "id" },
{ "name" },
{ "position" },
{ "salary" },
{ "start_date" },
{ "office" },
{ "extn"}
]

My DataTable is saying "No data available in table" so I think I am doing something wrong in my columns. What am I missing?

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,598
    Answer ✓

    You need to declare columns.data correctly. Instead of:

    { "position" },
    

    have

    { data: "position" },
    

    for all those columns.

    Colin

This discussion has been closed.