Datatable- No data available in table

Datatable- No data available in table

LersterLerster Posts: 21Questions: 5Answers: 0

Hello,

I´ve the following table


echo '<table id="myTable" class="display">'; echo '<tbody>'; echo '<thead>'; echo '<tr>'; echo '<th>'; echo "Name"; echo '</th>'; echo '<th>'; echo "Server"; echo '</th>'; echo '<th>'; echo "Level"; echo '</th>'; echo '<th>'; echo ""; echo '</th>'; echo '</tr>'; echo '</thead>'; foreach($data2['wow_accounts']['0']['characters'] as $character) { $found = true; foreach ($names as $name) { if ($character['name'] == $name['firstname'] && $character['realm']['name'] == $name['lastname']) { $found = false; break; } } $class_string = $found ? '' : ' class="my-additional-class"'; echo '<tr' . $class_string . '>'; echo '<td>'; echo $character['name']; echo '</td>'; echo '<td>'; echo $character['realm']['name']; echo '</td>'; echo '<td>'; echo $character['level']; echo '</td>'; echo '<td>'; echo '<button class="btnSelect">Select</button>'; echo '</td>'; echo '</tr>'; } echo '</tbody>'; echo '</table>';

I get the tables data out of an extern API array with a curl function (variable $data2)


function getSslPage2($url2, $userAgent2) { $ch2 = curl_init($url2); curl_setopt($ch2, CURLOPT_USERAGENT, $userAgent); curl_setopt($ch2, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch2, CURLOPT_HEADER, false); curl_setopt($ch2, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch2, CURLOPT_URL, $url2); curl_setopt($ch2, CURLOPT_REFERER, $url2); curl_setopt($ch2, CURLOPT_RETURNTRANSFER, TRUE); $result2 = curl_exec($ch2); curl_close($ch2); return json_decode($result2, true); } $url2 = "https://xxx.api.com/wow?namespace=profile-eu&locale=de_DE&access_token=XX"; $data2 = getSslPage2($url2, $userAgent);

The $data2 results gets alligned with datas in my mysql table, as you can see in the foreach loop. It´s the $name variable.

In the datatables I get the following error:

"No data available in table."

Could you help me how to fix this with an "easy" way?

Answers

  • kthorngrenkthorngren Posts: 20,276Questions: 26Answers: 4,765

    I'm guessing you are initializing Datables before the data is added to the table. You should initialize Datatables after you load the table data. Since you aren't using Datatables API's to add the rows it doesn't know about the HTML updates.

    Kevin

  • LersterLerster Posts: 21Questions: 5Answers: 0

    Thanks for your answer. Which possibilities do I have to make sure that datatables initialize the data after loading my table? Is there a possibility to delay the loading of datatables to make sure my table is completely initialized?

  • allanallan Posts: 61,665Questions: 1Answers: 10,096 Site admin

    It looks like PHP is being used to create the HTML, so I think it should actually be in place and ready for DataTables to use (unless you are Ajax loading it it).

    We'd need a link to a page showing the issue to be able to help debug this one.

    Allan

  • LersterLerster Posts: 21Questions: 5Answers: 0

    Hi, I´ll send you a link of a testpage. Thank you.

This discussion has been closed.