displaying object in datatables
displaying object in datatables
Hi there,
Sorry for the newbie questions, I've a problem on displaying data into data tables, i'm doing this with local json, php and javascript, so here's the code i'm using
[JavaScript]
var json_parsed = $.parseJSON(data);
console.log(data);
console.log(json_parsed);
for (var i = 0; i < json_parsed.spam_count.length; i++) {
var spammer_info = json_parsed.spam_count[i];
//alert(spammer_info.user_name);
console.log(spammer_info);
}
[Data Tables]
$('#example').dataTable({
"Data": spammer_info,
"Columns":[
{"data":"user_id"},
{"data":'event_id'},
{"data":'user_name'}
]
});
[console.log(data)]
{"spam_count":[{"user_id":"2","event_id":"1","spam_count":"1000","user_name":"bbb"},{"user_id":"1","event_id":"2","spam_count":"0","user_name":"aaa"}]}
[console.log(json_parsed)]
Object {spam_count: Array[2]}
spam_count: Array[2]
0: Object
event_id: "1"
spam_count: "1000"
user_id: "2"
user_name: "bbb"
proto: Object
1: Object
event_id: "2"
spam_count: "0"
user_id: "1"
user_name: "aaa"
proto: Object
length: 2
proto: Array[0]
proto: Object
[console.log(spammer_info)]
Object {user_id: "2", event_id: "1", spam_count: "1000", user_name: "bbb"}
Object {user_id: "1", event_id: "2", spam_count: "0", user_name: "aaa"}
I feel that I'm close enough of getting what i want, however i still couldn't make it works, really desperate for the answers, plus i'm quite confused with which one( or variables) to be used to display properly in data tables, array? objects ? Other than that, when everything can be display properly, I'll add the checkbox in every display rows
Answers
by the way, i'm trying to display an object directly to the datatables, instead of using ajax source or text file or even processing script