Problem populating a DataTable
Problem populating a DataTable
diego30k
Posts: 5Questions: 0Answers: 0
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.
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.
This discussion has been closed.
Replies
Allan