Newbie Q: Populating DT after pageload kills it
Newbie Q: Populating DT after pageload kills it
Hi, I have this page that loads a DT table when user hits the "Demarer" button.
See: http://www.oreillegauche.com/MRKT/MonitorEmailsDT.php
This fires js XMLHttpRequest() to a PHP scripts that echoes <tr><td> inside the <tbody> tag. It works but as soon as I try to use "search" or order columns, the data disappears and the table goes empty.
Is there a REFRESH function or is it just not the way to do it?
I chose this method over AJAX and server-side because I have very few data and I'm using different CSS color decoration depending on data values (past dates are red, futur dates are green).
THANKS
See HTML code below (I stripped <tfoot> for clarity) :
<table id="myTable" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th>ID</th>
<th>Prénom</th>
<th>Nom</th>
<th>Adresse courriel</th>
<th>Envoi prévu le</th>
</tr>
</thead>
<tbody id="ToSendList">
<!-- TABLE DATA HERE-->
</tbody>
</table>
See js code fired by the "Demarer" button:
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("ToSendList").innerHTML = this.responseText;
}
};
xmlhttp.open("GET", "GetEmailListfoDT.php", true);
xmlhttp.send();
Replies
Hi,
See the I append a row to the table using DOM/jQuery, but it is removed on redraw FAQ.
Its basically the same thing. You need to use the DataTables API to add rows to the table after you have created the table.
Allan