Datatables not displaying data

Datatables not displaying data

IrishDaveIrishDave Posts: 2Questions: 1Answers: 0

Hi, hopefully someone can help me.
I am wanting to display some data to a user using datatables. The PHP script returns some data from the database which is formatted to be outputted in a data table. I find that more often the data will not render correctly and I get the following error message in the console.

matchMaking.php:1930 Uncaught TypeError: Cannot read properties of null (reading 'toString')
at matchMaking.php:1930
at jquery.dataTables.min.js:18
at Object.b.fnGetData (jquery.dataTables.min.js:12)
at B (jquery.dataTables.min.js:17)
at Ha (jquery.dataTables.min.js:25)
at O (jquery.dataTables.min.js:16)
at wb (jquery.dataTables.min.js:40)
at jquery.dataTables.min.js:37
at i (jquery.dataTables.min.js:35)
at Object.success (jquery.dataTables.min.js:36)

if I hard code the data in as shown below:

$data_property = array (
array("Cody","Curran","Male","2005-04-13","13-04-2005","Open","70","0","0","0","0","0","Orthadox","1.8288","30","<a target='_blank' href=''>Thorne and Moorends</a>","Yorkshire/Humberside","","United Kingdom","<button class='btn-sm btn-info contactModal' data-memberID=16>Contact</button>"),
array("Ellie","Coulson","Male","2005-04-13","13-04-2005","Open","70","0","0","0","0","0","Orthadox","1.8288","30","<a target='_blank' href=''>Thorne and Moorends</a>","Yorkshire/Humberside","","United Kingdom","<button class='btn-sm btn-info contactModal' data-memberID=16>Contact</button>"),
array("Elliott","Stanton","Male","2005-04-13","13-04-2005","Open","70","0","0","0","0","0","Orthadox","1.8288","30","<a target='_blank' href=''>Thorne and Moorends</a>","Yorkshire/Humberside","","United Kingdom","<button class='btn-sm btn-info contactModal' data-memberID=16>Contact</button>"),
array("Terrell","Andrews","Male","2005-04-13","13-04-2005","Open","70","0","0","0","0","0","Orthadox","1.8288","30","<a target='_blank' href='>Thorne and Moorends</a>","Yorkshire/Humberside","","United Kingdom","<button class='btn-sm btn-info contactModal' data-memberID=16>Contact</button>")
);

then send the data back to the table using the code below then the data is displayed correctly

$output = array(
"draw" => intval($_POST["draw"]),
"recordsTotal" => $dataObject["recordsTotal"],
"recordsFiltered" => $dataObject["recordsFiltered"],
"colVis" => $dataObject["colVis"],
data" => $data_property
);

This issue arises when I use the data returned from the database which is in the same format, this data throws an error message that's described above.
Its really confusing why one works but not the other.

Can someone shed any light on this matter please.
I have attached a file showing the two sets of data
Regards, David

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,145Questions: 26Answers: 4,736
    Answer ✓

    Start by looking at the JSON response by using the browser's network inspector tool. If further help is need please post the response and your Datatables initialization code.

    Kevin

  • IrishDaveIrishDave Posts: 2Questions: 1Answers: 0

    Thanks Kevin, I did what you said and it helped.
    Cheers

Sign In or Register to comment.