Problem populating a DataTable

Problem populating a DataTable

diego30kdiego30k Posts: 5Questions: 0Answers: 0
edited June 2012 in DataTables 1.9
Hi, I'm new here so I ask for some help.
I populate my table using $ajax and JSON data (using php and mysql):
(Sorry, part of my code is in spanish, I'm from Peru)
[code]
$.ajax({
data: {
operacion: "listarTodos"
},
type: "POST",
dataType: "JSON",
url: "albumBL.php",
success: function(resp){
$("#dataTable tbody").html("");
var content = "";
$.each(resp,function(i) {
content += "";
content += ""+resp[i].id+"";
content += ""+resp[i].album+"";
content += ""+resp[i].artista+"";
content += ""+resp[i].annio+"";
content += ""+resp[i].calificacion+"";
content += "Ver";
content += "";
});
$("#dataTable tbody").html(content);
});

[/code]
As you see, I add html code into the tbody DOM. Then I initialize my dataTable using the classic code

[code]
$('#dataTable').dataTable({});
[/code]

When I load my page the data appears but when I use search and sorting function, suddenly all my data diseapears, also CSS doesn't work properly.

I hope somebody can help me. Thank you for your time.

Replies

  • allanallan Posts: 63,695Questions: 1Answers: 10,500 Site admin
    From your description you are using DOM methods to alter a table - is that correct? If so, then this FAQ will be of some assistance: http://datatables.net/faqs#append

    Allan
  • diego30kdiego30k Posts: 5Questions: 0Answers: 0
    Thank you Allan for your help, I solved my problem using the method fnAddData.
This discussion has been closed.