Can't get all row data
Can't get all row data
dandi
Posts: 1Questions: 1Answers: 0
Hello!
First i have to say, im new to data tables and javascript at all. And thats my first project i'm using it.
How can i get all data from the table in an array?
This is what i have tried:
oTable = $('#dataTable').DataTable();
getAllMarker();
var rows = oTable.rows().data();
alert(rows.length);
alert always return 0 but my table is populated with values. This is done in the getAllMarker() Method.
function getAllMarker(){
$.ajax({
type: "POST",
url: "marker.php",
//IMPORTANT: set marker_table depending on current markerobject
data:{function:"getAllMarker" },
dataType: 'json',
success: function(s){
console.log(s);
oTable.clear();
for(var i = 0; i < s.length; i++) {
var space = " ";
oTable.row.add([
s[i][0],
s[i][0], //id
s[i][1], //attribut
s[i][11], //rating
s[i][12], //comment
s[i][4], //latitude
s[i][5], //longitude
s[i][6], //street
s[i][7], //city
s[i][8], //zip
s[i][2], //creation_time
s[i][3], //update_time
s[i][9]+=space+=s[i][10], //creator
]).draw();;
} // End For
},
error: function(e){
console.log(e.responseText);
}
});
}
Hope anyone can help me.
This discussion has been closed.
Answers
Use
data()
as you have. If that isn't working for you, please link to a test page showing the issue, as required in the forum rules, so we can offer some help.Allan